Advertisement
Atanasov_88

FINAL DATABASE TABLE

Mar 19th, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.64 KB | None | 0 0
  1. CREATE TABLE Customers
  2. (CustomerID int AUTO_INCREMENT,
  3. CompanyName varchar(100),
  4. ContactName varchar(100),
  5. ContactTitle varchar(100),
  6. Adress varchar(400),
  7. City varchar(30),
  8. Region varchar(30),
  9. PostalCode smallint,
  10. Country varchar(30),
  11. Phone smallint,
  12. Fax smallint,
  13. CONSTRAINT c_Customers_PK PRIMARY KEY(CustomerID));
  14.  
  15. CREATE TABLE Orders
  16. (OrderID int AUTO_INCREMENT,
  17. CustomerID int,
  18. EmployeeID int,
  19. OrderDate date,
  20. RequiredDate date,
  21. ShipDate date,
  22. ShipName varchar(50),
  23. ShipAdress varchar(100),
  24. ShipCity varchar(39),
  25. ShipRegion varchar(39),
  26. ShipCountry varchar(20));
  27. alter table Orders add CONSTRAINT c_Orders_PK PRIMARY KEY(OrderID),
  28. alter table Orders add CONSTRAINT c_Orders_FK FOREIGN KEY(CustomerID) REFERENCES Customers(CustomerID);
  29. alter table Orders add CONSTRAINT c_Orders_FK_EmployeeID FOREIGN KEY(EmployeeID) REFERENCES employees(EmployeeID);
  30.  
  31. CREATE TABLE Products
  32. (ProductID int AUTO_INCREMENT,
  33. ProductName varchar(50),
  34. SupplierID int,
  35. CategoryID int,
  36. UnitPrice double,
  37. CONSTRAINT c_Products_PK PRIMARY KEY(ProductID));
  38.  
  39. alter table Products add CONSTRAINT c_Products_CategoryID FOREIGN KEY(CategoryID) REFERENCES Categories(CategoryID);
  40. alter table Products add CONSTRAINT c_Products_SupplierID FOREIGN KEY(SupplierID) REFERENCES Suppliers(SupplierID);
  41.  
  42. create table Order_Details
  43. (OrderID int,
  44. ProductID int,
  45. UnitPrice float,
  46. Quantity smallint,
  47. Discount decimal);
  48. alter table Order_Details add CONSTRAINT c_Order_Product_FK FOREIGN KEY(ProductID) REFERENCES Products(ProductID);
  49. alter table Order_Details add CONSTRAINT c_Order_Order_FK FOREIGN KEY(OrderID) REFERENCES Orders(OrderID);
  50.  
  51. create table Categories
  52. (CategoryID int AUTO_INCREMENT,
  53. CategoryName varchar(50),
  54. Description varchar(250),
  55. CONSTRAINT c_Categories_PK PRIMARY KEY(CategoryID));
  56.  
  57. create table Employees
  58. (EmployeeID int AUTO_INCREMENT,
  59. LastName varchar(30),
  60. FirstName varchar(30),
  61. Title varchar(30),
  62. TitleOfCourtsey varchar(30),
  63. BirthDate date,
  64. HireDate date,
  65. Adress text,
  66. City varchar(41),
  67. Region varchar(41),
  68. PostalCode smallint,
  69. Country varchar(30),
  70. HomePhone smallint,
  71. ReportsTo int REFERENCES Employees(EmployeeID),
  72. Salary decimal,
  73. CONSTRAINT c_Employees_PK PRIMARY KEY (EmployeeID));
  74. alter table Employees add CONSTRAINT c_Rddasd FOREIGN KEY(ReportsTo) REFERENCES Employees(EmployeeID);
  75.  
  76. create table OrderDetails
  77. (OrderID int,
  78. ProductID int,
  79. UnitPrice int,
  80. Quantity int,
  81. Discount decimal);
  82. ALTER table OrderDetails add CONSTRAINT c_Order_FK FOREIGN KEY(OrderID) REFERENCES Orders(OrderID);
  83. ALTER table orderdetails add CONSTRAINT c_Product_FK FOREIGN KEY(ProductID) REFERENCES Products(ProductID);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement