Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE Customers
- (CustomerID int AUTO_INCREMENT,
- CompanyName varchar(100),
- ContactName varchar(100),
- ContactTitle varchar(100),
- Adress varchar(400),
- City varchar(30),
- Region varchar(30),
- PostalCode smallint,
- Country varchar(30),
- Phone smallint,
- Fax smallint,
- CONSTRAINT c_Customers_PK PRIMARY KEY(CustomerID));
- CREATE TABLE Orders
- (OrderID int AUTO_INCREMENT,
- CustomerID int,
- EmployeeID int,
- OrderDate date,
- RequiredDate date,
- ShipDate date,
- ShipName varchar(50),
- ShipAdress varchar(100),
- ShipCity varchar(39),
- ShipRegion varchar(39),
- ShipCountry varchar(20));
- alter table Orders add CONSTRAINT c_Orders_PK PRIMARY KEY(OrderID),
- alter table Orders add CONSTRAINT c_Orders_FK FOREIGN KEY(CustomerID) REFERENCES Customers(CustomerID);
- alter table Orders add CONSTRAINT c_Orders_FK_EmployeeID FOREIGN KEY(EmployeeID) REFERENCES employees(EmployeeID);
- CREATE TABLE Products
- (ProductID int AUTO_INCREMENT,
- ProductName varchar(50),
- SupplierID int,
- CategoryID int,
- UnitPrice double,
- CONSTRAINT c_Products_PK PRIMARY KEY(ProductID));
- alter table Products add CONSTRAINT c_Products_CategoryID FOREIGN KEY(CategoryID) REFERENCES Categories(CategoryID);
- alter table Products add CONSTRAINT c_Products_SupplierID FOREIGN KEY(SupplierID) REFERENCES Suppliers(SupplierID);
- create table Order_Details
- (OrderID int,
- ProductID int,
- UnitPrice float,
- Quantity smallint,
- Discount decimal);
- alter table Order_Details add CONSTRAINT c_Order_Details_Orders_FK FOREIGN KEY(OrderID, ProdcutID) REFERENCES Orders(OrderID)
- alter table Order_Details add CONSTRAINT c_Order_Product_FK FOREIGN KEY(ProductID) REFERENCES Products(ProductID);
- create table Categories
- (CategoryID int AUTO_INCREMENT,
- CategoryName varchar(50),
- Description varchar(250),
- CONSTRAINT c_Categories_PK PRIMARY KEY(CategoryID));
- create table Employees
- (EmployeeID int AUTO_INCREMENT,
- LastName varchar(30),
- FirstName varchar(30),
- Title varchar(30),
- TitleOfCourtsey varchar(30),
- BirthDate date,
- HireDate date,
- Adress text,
- City varchar(41),
- Region varchar(41),
- PostalCode smallint,
- Country varchar(30),
- HomePhone smallint,
- ReportsTo int,
- Salary decimal,
- CONSTRAINT c_Employees_PK PRIMARY KEY (EmployeeID));
- alert table employees add CONSTRAINT c_Report_To_FK FOREIGN KEY(ReportsTo) REFERENCES employees(EmployeeID);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement