Introduction
Good table design helps your database work faster and use less space. Poor design can slow down queries and make your data messy.
Good table design helps your database work faster and use less space. Poor design can slow down queries and make your data messy.
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, adds two employees, and selects those in the Sales department.
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Department VARCHAR(50) ); INSERT INTO Employees VALUES (1, 'Alice', 'Smith', 'Sales'); INSERT INTO Employees VALUES (2, 'Bob', 'Jones', 'HR'); SELECT * FROM Employees WHERE Department = 'Sales';
Using the right data types reduces storage and speeds up queries.
Indexes on key columns help the database find data faster.
Design tables to avoid repeating data; this is called normalization.
Good table design improves speed and saves space.
Use keys and proper data types to help the database work efficiently.
Plan your tables to keep data organized and avoid duplicates.
products(id INT PRIMARY KEY, name VARCHAR(50), price DECIMAL(5,2)), what will be the result of this query?SELECT * FROM products WHERE price < 10.00;Pass the test and this pattern moves unknown