Advertisement
szubert

Untitled

Nov 9th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.67 KB | None | 0 0
  1. CREATE TABLE employee  (emp_no INTEGER  NOT NULL primary key,
  2.                         emp_fname CHAR(20) NOT NULL,
  3.                         emp_lname CHAR(20) NOT NULL,
  4.                         dept_no CHAR(4) NULL
  5.                         )
  6. CREATE TABLE department(dept_no char(4) NOT NULL primary key,
  7.                         dept_name CHAR(25) NOT NULL,
  8.                         location CHAR(30) NULL)
  9.  
  10. /*
  11. alter table employee
  12. add constraint h foreign key (dept_no) references department(dept_no) on update cascade on delete cascade;
  13. */
  14. CREATE TABLE project   (project_no char(4) NOT NULL primary key,
  15.                         project_name CHAR(15) NOT NULL,
  16.                         budget FLOAT NULL)
  17.  
  18. insert into employee values(25348, 'Matthew', 'Smith','d3')
  19. insert into employee values(10102, 'Ann', 'Jones','d3')
  20. insert into employee values(18316, 'John', 'Barrimore', 'd1')
  21. insert into employee values(29346, 'James', 'James', 'd2')
  22. insert into employee values(9031, 'Elsa', 'Bertoni', 'd2')
  23. insert into employee values(2581, 'Elke', 'Hansel', 'd2')
  24. insert into employee values(28559, 'Sybill', 'Moser', 'd1')
  25. insert into department values ('d1', 'research','Dallas')
  26. insert into department values ('d2', 'accounting', 'Seattle')
  27. insert into department values ('d3', 'marketing', 'Dallas')
  28. insert into project values ('p1', 'Apollo', 120000.00)
  29. insert into project values ('p2', 'Gemini', 95000.00)
  30. insert into project values ('p3', 'Mercury', 186500.00)
  31. insert into project values ('4', 'Mercurycc', 186400.00)
  32. insert into project values ('6', 'Mercuryc', 186406.00)
  33.  
  34.  
  35. create table works_on ( emp_no int,
  36.                         constraint f foreign key (emp_no) references employee(emp_no) on update cascade on delete cascade,
  37.                         project_no char(4),
  38.                         constraint g foreign key (project_no) references project(project_no) on update cascade on delete cascade,
  39.                         job char(20) not null,
  40.                         enter_date date
  41.                         )
  42. alter table employee
  43. add constraint name_constraint unique(emp_fname, emp_lname);
  44.  
  45. alter table works_on
  46. add constraint enter_date_default
  47. default GETDATE() for enter_date;
  48.  
  49. alter table project
  50. add constraint budget_value check(budget between 0 and 250000);
  51.  
  52. alter table employee
  53. drop constraint name_constraint;
  54.  
  55. insert into works_on (emp_no, project_no, job, enter_date)
  56. values ('1', '123', 'sth', '03-01-1998'), ('1', '123', 'sth','03-01-1998'),('1', '123', 'sth','03-01-1998'), ('1', '123', 'sth', '03-01-1998'),('1', '123', 'sth', '03-01-1998');
  57.  
  58. exec sp_RENAME 'employee.emp_fname', 'emp_surname', 'column';
  59.  
  60. update employee
  61. set emp_lname = 'Bond'
  62. where emp_surname = 'Elsa';
  63.  
  64. update project
  65. set project_name = 'jakaswartosc'
  66. where project_no between '3' and '5';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement