Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sample
-- schema CREATE TABLE Departments ( Id INT NOT NULL IDENTITY, Name VARCHAR(25) NOT NULL, PRIMARY KEY(Id) ); CREATE TABLE Employees ( Id INT NOT NULL IDENTITY, FName VARCHAR(35) NOT NULL, LName VARCHAR(35) NOT NULL, PhoneNumber VARCHAR(11), ManagerId INT, DepartmentId INT NOT NULL, Salary INT NOT NULL, HireDate DATETIME2(0) NOT NULL, PRIMARY KEY(Id), FOREIGN KEY (ManagerId) REFERENCES Employees(Id), FOREIGN KEY (DepartmentId) REFERENCES Departments(Id) ); CREATE TABLE Customers ( Id INT NOT NULL IDENTITY, FName VARCHAR(35) NOT NULL, LName VARCHAR(35) NOT NULL, Email varchar(100) NOT NULL, PhoneNumber VARCHAR(11), PreferredContact VARCHAR(5) NOT NULL, PRIMARY KEY(Id) ); CREATE TABLE Cars ( Id INT NOT NULL IDENTITY, CustomerId INT NOT NULL, EmployeeId INT NOT NULL, Model varchar(50) NOT NULL, Status varchar(25) NOT NULL, TotalCost INT NOT NULL, PRIMARY KEY(Id), FOREIGN KEY (CustomerId) REFERENCES Customers(Id), FOREIGN KEY (EmployeeId) REFERENCES Employees(Id) ); -- data SET IDENTITY_INSERT Departments ON; INSERT INTO Departments (Id, Name) VALUES (1, 'HR'), (2, 'Sales'), (3, 'Tech') ; SET IDENTITY_INSERT Departments OFF; SET IDENTITY_INSERT Employees ON; INSERT INTO Employees (Id, FName, LName, PhoneNumber, ManagerId, DepartmentId, Salary, HireDate) VALUES (1, 'James', 'Smith', 1234567890, NULL, 1, 1000, Cast('01-01-2002' as datetime)), (2, 'John', 'Johnson', 2468101214, '1', 1, 400, cast('23-03-2005'as datetime)), (3, 'Michael', 'Williams', 1357911131, '1', 2, 600, cast('12-05-2009'as datetime)), (4, 'Johnathon', 'Smith', 1212121212, '2', 1, 500, cast('24-07-2016'as datetime)) ; SET IDENTITY_INSERT Employees OFF; SET IDENTITY_INSERT Customers ON; INSERT INTO Customers (Id, FName, LName, Email, PhoneNumber, PreferredContact) VALUES (1, 'William', 'Jones', 'william.jones@example.com', '3347927472', 'PHONE'), (2, 'David', 'Miller', 'dmiller@example.net', '2137921892', 'EMAIL'), (3, 'Richard', 'Davis', 'richard0123@example.com', NULL, 'EMAIL') ; SET IDENTITY_INSERT Customers OFF; SET IDENTITY_INSERT Cars ON; INSERT INTO Cars (Id, CustomerId, EmployeeId, Model, Status, TotalCost) VALUES ('1', '1', '2', 'Ford F-150', 'READY', '230'), ('2', '1', '2', 'Ford F-150', 'READY', '200'), ('3', '2', '1', 'Ford Mustang', 'WAITING', '100'), ('4', '3', '3', 'Toyota Prius', 'WORKING', '1254') ; SET IDENTITY_INSERT Cars OFF;
run
|
edit
|
history
|
help
0
Ranking
TRANSACTIONS
M0413045.sql
Import CSV File Into SQL Server Using Bulk Insert
BRYANActual
NAMES CODE
table creation
c12part2
Practice
mySQL_Glx_12dec