Advertisement
Atanasov_88

Untitled

Mar 20th, 2016
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.77 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. INSERT INTO Customers
  16. VALUES('1', 'Coca Cola', 'Ivan Atanasov', 'Manager', 'Sofia - Centur', 'Sofia', 'Sofia-grad', '1000', 'Bulgaria', '0885491456',
  17. '2223233');
  18.  
  19. INSERT INTO Customers
  20. VALUES('2', 'Fanta', 'Georgi Mladenov', 'SeniorManager', 'Mladost 1', 'Sofia', 'Sofia-grad', '1000', 'Bulgaria', '0885291456',
  21. '2223234');
  22.  
  23. INSERT INTO Customers
  24. VALUES('3', 'Sprite', 'Mladen Georgiev', 'Junior Manager', 'Mladost 2', 'Sofia', 'Sofia-grad', '1000', 'Bulgaria', '0885292456',
  25. '2523234');
  26.  
  27. INSERT INTO Customers
  28. VALUES('4', 'Pepsi', 'Kamen Damianov', 'Intern', 'Mladost 3', 'Sofia', 'Sofia-grad', '1000', 'Bulgaria', '0885291556',
  29. '2623234');
  30.  
  31. INSERT INTO Customers
  32. VALUES('5', 'Mirinda', 'Kalina Atanasova', 'Big Boss', 'Mladost 4', 'Sofia', 'Sofia-grad', '1000', 'Bulgaria', '0885291156',
  33. '2223134');
  34.  
  35.  
  36. CREATE TABLE Orders
  37. (OrderID int AUTO_INCREMENT,
  38. CustomerID int,
  39. EmployeeID int,
  40. OrderDate date,
  41. RequiredDate date,
  42. ShipDate date,
  43. ShipName varchar(50),
  44. ShipAdress varchar(100),
  45. ShipCity varchar(39),
  46. ShipRegion varchar(39),
  47. ShipCountry varchar(20));
  48. alter table Orders add CONSTRAINT c_Orders_PK PRIMARY KEY(OrderID),
  49. alter table Orders add CONSTRAINT c_Orders_FK FOREIGN KEY(CustomerID) REFERENCES Customers(CustomerID);
  50. alter table Orders add CONSTRAINT c_Orders_FK_EmployeeID FOREIGN KEY(EmployeeID) REFERENCES employees(EmployeeID);
  51.  
  52. INSERT INTO Orders
  53. VALUES('1', '1', '1', '2015-01-12', '2015-01-17', '2015-01-15', 'Titanik', 'Burgas, Morska gradina', 'Burgas',
  54. 'Burgas - grad', 'Bulgaria');
  55.  
  56. INSERT INTO Orders
  57. VALUES('2', '2', '3', '2015-01-13', '2015-01-18', '2015-01-16', 'Britanik', 'Burgas, Morska gradina', 'Burgas',
  58. 'Burgas - grad', 'Bulgaria');
  59.  
  60. INSERT INTO Orders
  61. VALUES('3', '4', '5', '2013-01-13', '2013-01-18', '2013-01-16', 'Britanik', 'Burgas, Morska gradina', 'Burgas',
  62. 'Burgas - grad', 'Bulgaria');
  63.  
  64. CREATE TABLE Products
  65. (ProductID int AUTO_INCREMENT,
  66. ProductName varchar(50),
  67. SupplierID int,
  68. CategoryID int,
  69. UnitPrice double,
  70. CONSTRAINT c_Products_PK PRIMARY KEY(ProductID));
  71.  
  72. alter table Products add CONSTRAINT c_Products_CategoryID FOREIGN KEY(CategoryID) REFERENCES Categories(CategoryID);
  73. alter table Products add CONSTRAINT c_Products_SupplierID FOREIGN KEY(SupplierID) REFERENCES Suppliers(SupplierID);
  74.  
  75. insert into Products
  76. Values ('1', 'Yellow coca', '1', '2', '300');
  77.  
  78. insert into Products
  79. Values ('2', 'Brown coca', '3', '3', '300');
  80.  
  81. insert into Products
  82. Values ('3', 'White coca', '4', '1', '300');
  83.  
  84. insert into Products
  85. Values ('4', 'Orange coca', '2', '2', '300');
  86.  
  87. insert into Products
  88. Values ('5', 'Sprite coca', '2', '3', '300');
  89.  
  90. create table Order_Details
  91. (OrderID int,
  92. ProductID int,
  93. UnitPrice float,
  94. Quantity smallint,
  95. Discount decimal);
  96. alter table Order_Details add CONSTRAINT c_Order_Product_FK FOREIGN KEY(ProductID) REFERENCES Products(ProductID);
  97. alter table Order_Details add CONSTRAINT c_Order_Order_FK FOREIGN KEY(OrderID) REFERENCES Orders(OrderID);
  98.  
  99. create table Categories
  100. (CategoryID int AUTO_INCREMENT,
  101. CategoryName varchar(50),
  102. Description varchar(250),
  103. CONSTRAINT c_Categories_PK PRIMARY KEY(CategoryID));
  104.  
  105. INSERT INTO categories
  106. VALUES ('1', 'Drinks', 'Non-alcoholic drinks for every day');
  107.  
  108. INSERT INTO categories
  109. VALUES ('2', 'Foods', 'Junk food for fat people');
  110.  
  111. INSERT INTO categories
  112. VALUES ('3', 'Shirts', 'Male and female shirts');
  113.  
  114. create table Employees
  115. (EmployeeID int AUTO_INCREMENT,
  116. LastName varchar(30),
  117. FirstName varchar(30),
  118. Title varchar(30),
  119. TitleOfCourtsey varchar(30),
  120. BirthDate date,
  121. HireDate date,
  122. Adress text,
  123. City varchar(41),
  124. Region varchar(41),
  125. PostalCode smallint,
  126. Country varchar(30),
  127. HomePhone smallint,
  128. ReportsTo int REFERENCES Employees(EmployeeID),
  129. Salary decimal,
  130. CONSTRAINT c_Employees_PK PRIMARY KEY (EmployeeID));
  131. alter table Employees add CONSTRAINT c_Rddasd FOREIGN KEY(ReportsTo) REFERENCES Employees(EmployeeID);
  132.  
  133. ALTER TABLE employees  ADD Email varchar(200);
  134. alter table employees DROP Email;
  135.  
  136. INSERT INTO employees
  137. VALUES ('1', 'Berbatov', 'Dimitar', 'player', 'master', '1980-01-01', '2015-01-01', 'Sofia, bul. Bulgaria 3', 'Sofia',
  138. 'Sofia-grad', '1000', 'Bulgaria', '8769778', '1', '1050');
  139.  
  140. INSERT INTO employees
  141. VALUES ('2', 'Velev', 'Kristian', 'SEO', 'master', '1988-01-01', '2016-01-01', 'Sofia, bul. Bulgaria 3', 'Sofia',
  142. 'Sofia-grad', '1000', 'Bulgaria', '8765778', '1', '10500');
  143.  
  144. INSERT INTO employees
  145. VALUES ('3', 'Nikolaeva', 'Valentina', 'grandmother', 'master', '1936-01-01', '2016-01-01', 'Sofia, bul. Bulgaria 3', 'Sofia',
  146. 'Sofia-grad', '1000', 'Bulgaria', '8765773', '2', '10500');
  147.  
  148. INSERT INTO employees
  149. VALUES ('4', 'Omonigo', 'Temile', 'black pirat', 'non-master', '1972-01-01', '2016-03-01', 'Sofia, bul. Bulgaria 3', 'Sofia',
  150. 'Sofia-grad', '1000', 'Bulgaria', '8725773', '1', '100');
  151.  
  152. INSERT INTO employees
  153. VALUES ('5', 'Siderov', 'Volen', 'psyhopat', 'politic', '1974-01-01', '2013-03-01', 'Sofia, bul. Bulgaria 3', 'Sofia',
  154. 'Sofia-grad', '1000', 'Bulgaria', '8725773', '3', '930');
  155.  
  156. create table OrderDetails
  157. (OrderID int,
  158. ProductID int,
  159. UnitPrice int,
  160. Quantity int,
  161. Discount decimal);
  162. ALTER table OrderDetails add CONSTRAINT c_Order_FK FOREIGN KEY(OrderID) REFERENCES Orders(OrderID);
  163. ALTER table orderdetails add CONSTRAINT c_Product_FK FOREIGN KEY(ProductID) REFERENCES Products(ProductID);
  164.  
  165. insert into orderdetails
  166. values('1', '2', '40005', '23', '20');
  167.  
  168. insert into orderdetails
  169. values('2', '1', '50005', '22', '22');
  170.  
  171. insert into orderdetails
  172. values('3', '4', '20005', '12', '12');
  173.  
  174. insert into suppliers
  175. values('1', 'Nike', 'Cristiano Ronaldo', 'Sales manager', 'Drujba 2', 'Miami', 'USA - 1', 'USA', '223', '2234',
  176. 'Nike.com');
  177.  
  178. insert into suppliers
  179. values('2', 'Adidas', 'Lionel Messi', 'Contact manager', 'Drujba 3', 'Miami', 'USA - 1', 'USA', '224', '2233',
  180. 'Adidasbatka.com');
  181.  
  182. insert into suppliers
  183. values('3', 'Puma', 'Novak Djokovic', 'Super manager', 'Drujba 4', 'Miami', 'USA - 1', 'USA', '225', '2234',
  184. 'Puma-Maimuna.com');
  185.  
  186. insert into suppliers
  187. values('4', 'Reebok', 'Plamen Markov', 'Mega manager', 'Drujba 5', 'Miami', 'USA - 1', 'USA', '226', '2235',
  188. 'Reebok-bratok.com');
  189.  
  190. select Salary
  191. from employees;
  192.  
  193. update employees
  194. set Salary = salary + 100
  195. where salary >= 0;
  196.  
  197. delete from employees
  198. where salary < 1000;
  199.  
  200. delete e
  201. from employees e
  202. left join orders o ON e.EmployeeID = o.EmployeeID
  203. where e.EmployeeID = null
  204.  
  205. alter table products drop FOREIGN key c_Products_SupplierID;
  206. drop table suppliers;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement