1.Employees Employee table
/** Create employees employee table **/ UseTSQL2012IF object_id('dbo. Employees','U') is not NULLDROP TABLEdbo. EmployeesCREATE TABLEdbo. Employees (EmpidINT not NULL, FirstNameVARCHAR( -) not NULL, LastNameVARCHAR( -) not NULL, HireDate DATE not NULL, MgridINT NULL, SSNVARCHAR( -) not NULL, Salary Money not NULL)/** Add PRIMARY KEY constraint **/ALTER TABLEDbo. EmployeesADD CONSTRAINTpk_employeesPRIMARY KEY(empid);/** Add UNIQUE Constraint **/ALTER TABLEDbo. EmployeesADD CONSTRAINTUNQ_EMPLOYEES_SSNUNIQUE(SSN);/** Add foreign KEY constraint **/ALTER TABLEDbo. EmployeesADD CONSTRAINTfk_employees_employeesFOREIGN KEY(Mgrid)REFERENCESdbo. Employees (empid);/** Add CHECK constraint **/ALTER TABLEDbo. EmployeesADD CONSTRAINTchk_employees_salaryCHECK(Salary>0.00)/** Delete Check constraint **/ALTER TABLEDbo. EmployeesDROP CONSTRAINTChk_employees_salary
2.Orders Order Form
/** Create orders order form **/ UseTSQL2012IF object_id('dbo. Orders','U') is not NULL DROP TABLEdbo. Orders;CREATE TABLEdbo. Orders (OrderIDINT not NULL, EmpidINT not NULL, CustIDVARCHAR(Ten) not NULL, Orderts DATETIME2 not NULL, QtyINT not NULL, CONSTRAINTPk_ordersPRIMARY KEY(OrderID));/** Add PRIMARY KEY constraint **/ALTER TABLEDbo. OrdersADD CONSTRAINTFk_orders_employeesFOREIGN KEY(Empid)REFERENCESdbo. Employees (empid);/** Add default constraint **/ALTER TABLEDbo. OrdersADD CONSTRAINTDft_orders_ordertsDEFAULT(Sysdatetime ()) forOrderts;/** Delete Check constraint **/ALTER TABLEDbo. EmployeesDROP CONSTRAINTDft_orders_orderts
SQL Server (chapter I) Create a table Delete table create a PRIMARY KEY constraint, a unique constraint, a foreign key constraint, a check constraint, a DEFAULT constraint