SQL Server Examples:
Creating a Table 2


 

Table Creation With Data Entry

IF EXISTS(SELECT name 
	  FROM 	 sysobjects 
	  WHERE   name = N'Employees' 
	  AND 	 type = 'U')
    DROP TABLE Employees
GO
CREATE TABLE Employees
(
	EmployeeID INT PRIMARY KEY NOT NULL Identity(1, 1),
	EmployeeNo Char(6),
	DateHired SmallDateTime,
	FirstName VarChar(20),
	MiddleName VarChar(20),
	LastName VarChar(20) NOT NULL,
	DepartmentID int DEFAULT 1 REFERENCES Departments(DepartmentID),
	Salary Decimal(6,2),
	IsMarried BIT,
	Notes Text
)
GO
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '43-957',  '02/14/02', 'Albert',     '',     'Samson',      1,        16.58,   1);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, Salary, IsMarried)
VALUES(                 '68-205',  '02/14/02', 'Leslie', 'William',  'Ellison', 16.58,     0);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '14-528',  '02/25/02', 'Elias',  'Jeremy',   'Hawkins',      3,        14.26,   0);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, Salary, IsMarried)
VALUES(                 '92-253',  '03/02/02', 'Anselme',     '',    'Wagner',  22.05,   1);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '68-828', '05/18/2002', 'James',     '',    'Haught',      2,        24.32,   0);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '40-208',  '05/24/02', 'Lester', 'Anthony',  'Fassal',      4,        18.22,   0);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '72-415', '08/05/2002','Sylvie', 'Helene',  'Stanson',      2,        22.25,   1);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '43-957',  '08/12/03', 'Robert',     '',     'Laughton',     4,        12.46,   0);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '43-957', '10/20/2003','Maurice', 'Stephen', 'Rowland',      3,        15.25,   1);
INSERT INTO Employees (EmployeeNo, DateHired, FirstName, MiddleName, LastName, DepartmentID, Salary, IsMarried)
VALUES(                 '43-957','10/26/2003','Gertrude','Bethanie', 'Samson',      1,        30.14,   1);
 

Home Copyright © 2004-2010 FunctionX, Inc.