SQL CREATE TABLE Tutorial
Example Table
We will create a table named employees
for our examples:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
position VARCHAR(50),
salary DECIMAL(10, 2),
age INT
);
Creating the Table
To create the table, use the following SQL command:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
position VARCHAR(50),
salary DECIMAL(10, 2),
age INT
);
Result:
Command | CREATE TABLE employees (employee_id INT PRIMARY KEY, name VARCHAR(50) NOT NULL, position VARCHAR(50), salary DECIMAL(10, 2), age INT); |
---|---|
Result |
|
Inserting Data into the Table
Let's insert some data into the employees
table:
INSERT INTO employees (employee_id, name, position, salary, age) VALUES
(1, 'John Doe', 'Manager', 60000.00, 45),
(2, 'Jane Smith', 'Developer', 55000.00, 30),
(3, 'Emily Johnson', 'Designer', 50000.00, 25);
Result:
Command | INSERT INTO employees (employee_id, name, position, salary, age) VALUES (1, 'John Doe', 'Manager', 60000.00, 45), (2, 'Jane Smith', 'Developer', 55000.00, 30), (3, 'Emily Johnson', 'Designer', 50000.00, 25); |
---|---|
Result |
|
Querying the Table
We can query the employees
table to see the data:
SELECT * FROM employees;
Result:
Command | SELECT * FROM employees; | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result |
|