Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
LidarBot
Snaszy NAS a 3D printed NAS for Raspberry Pi
Waveshare CM5 boards
The Best Arduino Robot for Beginners
SMARS Lab upgrade with PyCharm
Chicken Nugget Piano
Mini-Rack 3D Design Tutorial
0h 20m
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
20% Percent Complete
By Kevin McAleer, 3 Minutes
Module 3 focuses on creating tables in SQLite databases and understanding the principles of schema design. We will explore how to define table structure, data types, constraints, and primary keys.
Tables are the foundation of a relational database. They organize and store data in a structured manner. In this section, we will explore the components of table structure.
A table consists of rows, also known as records or tuples, and columns, also known as fields or attributes.
To create tables in a SQLite database, we use the SQL CREATE TABLE statement. This statement specifies the table name, column names, data types, and constraints.
CREATE TABLE
# Create a table connection.execute(''' CREATE TABLE books ( id INTEGER PRIMARY KEY, title TEXT, author TEXT, year INTEGER ) ''')
In this example, we create a table named “books” with four columns: “id,” “title,” “author,” and “year.” The INTEGER data type is used for the “id” and “year” columns, while TEXT is used for the “title” and “author” columns. The “id” column is defined as the primary key.
INTEGER
TEXT
A primary key uniquely identifies each record in a table. It ensures data integrity and serves as a reference point for establishing relationships between tables. In SQLite, primary keys can be defined using the PRIMARY KEY constraint.
PRIMARY KEY
# Create a table with a primary key connection.execute(''' CREATE TABLE students ( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, grade TEXT ) ''')
In this example, we create a “students” table with an “id” column as the primary key. Each record in the table will have a unique “id” value.
Sometimes, we need to modify the structure of existing tables. SQLite provides the ALTER TABLE statement to add, modify, or delete columns from a table.
ALTER TABLE
# Add a new column to a table connection.execute("ALTER TABLE students ADD COLUMN email TEXT")
In this example, we add a new “email” column to the “students” table. This new column will store email addresses for each student.
When designing a database schema, it’s important to consider several factors to ensure efficient data storage and retrieval. Some key considerations include:
NOT NULL
UNIQUE
By understanding these considerations, we can design efficient and well-structured databases.
< Previous Next >