Introduction
Good table design helps keep data organized and easy to use. It makes your database faster and avoids mistakes.
Good table design helps keep data organized and easy to use. It makes your database faster and avoids mistakes.
CREATE TABLE table_name ( column1 datatype constraints, column2 datatype constraints, ... );
CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, Name VARCHAR(100), Email VARCHAR(100) );
CREATE TABLE Orders ( OrderID INT PRIMARY KEY, CustomerID INT, OrderDate DATE, FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) );
This example creates an Employees table with unique IDs and emails, adds two employees, and shows all data.
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Email VARCHAR(100) UNIQUE ); INSERT INTO Employees (EmployeeID, FirstName, LastName, Email) VALUES (1, 'Alice', 'Smith', 'alice@example.com'), (2, 'Bob', 'Jones', 'bob@example.com'); SELECT * FROM Employees;
Good table design reduces errors and makes your database easier to maintain.
Using keys helps connect data between tables without repeating information.
Choosing the right data types saves space and improves speed.
Good table design keeps data organized and easy to find.
It helps your database work faster and avoid mistakes.
Use keys and proper data types to connect and store data efficiently.
employees(id INT PRIMARY KEY, name VARCHAR(50), department_id INT) and departments(id INT PRIMARY KEY, name VARCHAR(50)), what will this query return?SELECT e.name, d.name FROM employees e JOIN departments d ON e.department_id = d.id;
orders(order_id INT, customer_id INT, order_date DATE) but forgot to set a primary key. What problem might this cause?Pass the test and this pattern moves unknown