Idiot's Guides: SQL


Use these SQL statements to create the Employees table in the Corporation database that we'll use as a sample database (Note: if your DBMS does not support the USE statement to make Corporation the default database, just qualify the name of the table as Corporation.Employees instead and ignore the USE Corporation; line):

CREATE DATABASE Corporation;

USE Corporation;

CREATE TABLE Employees
(firstname VARCHAR(20),
lastname VARCHAR(20),
department VARCHAR(20),
hiredate DATE,
supervisor INT CHECK (supervisor > 1000 AND supervisor < 2000),
id INT PRIMARY KEY CHECK (id > 1000 AND id < 3000));

INSERT INTO Employees VALUES ("John", "Wood", "Sales", "20120115", 1001, 1501);

INSERT INTO Employees VALUES ("Mary", "Green", "Sales", "20120115", 1501, 1601);

INSERT INTO Employees VALUES ("Daniel", "Grant", "Sales", "20120115", 1501, 1602);

INSERT INTO Employees VALUES ("Nancy", "Jackson", "Accounting", "20120220", 1501, 1701);

INSERT INTO Employees VALUES ("Tom", "Smith", "Accounting", "20120315", 1701, 1801);

INSERT INTO Employees VALUES ("Jessica", "Smith", "Accounting", "20120315", 1701, 1901);

© 2017 Dorling Kindersley Limited. Registered Number 01177822, England. Registered Office: 80 Strand, London, WC2R 0RL. 'Dorling Kindersley', 'DK', 'Eyewitness' and the open book logo DK are trade marks of Dorling Kindersley Limited.
DK Books