Ashies

ASS2_

Jan 13th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. create table department(department_id int, department_name varchar(30));
  2.  
  3. create table manages(mgrName varchar(30) unique not null, workId int identity primary key, empId int , cmpId int, sal int, modifiedDate date default convert(date, getdate()));
  4.  
  5.  
  6. create table employee(empId int identity primary key, emName varchar(30) not null, street varchar(30),city varchar(30), mgrId int foreign key references manages(workId), dptId int, isActive varchar(10) default 'active', doj date default convert(date, getdate()) );
  7.  
  8. create table company( cmpId int identity primary key, cmpName varchar(30), city varchar(30)) ;
  9.  
  10.  
  11. create table works(workId int ,empId int foreign key references employee(empId), cmpId int foreign key references company(cmpId),sal int) ;
  12.  
  13.  
  14.  
  15.  
  16. insert into department values (1,'it'),
  17. (2, 'admin'),
  18. (3, 'hr');
  19.  
  20.  
  21. insert into manages values ('kapil',1, 1, 200000, '2019-01-14')
  22. , ('rahul',4, 1, 100000, '2019-01-14')
  23. , ('else',2, 1, 100000, '2019-01-14')
  24. , ('ttt',3, 2, 100000, '2019-01-14');
  25.  
  26.  
  27.  
  28. insert into employee values ('ehte' , 'A-38, noida, UP' , 'gzb' , 1 ,2, 'active', '2019-01-14') ,
  29. ('mansi' , 'A-38, noida, UP' , 'gzb' , 1 ,2, 'active', '2019-01-14'),
  30. ('aman' , 'A-39, noida, UP' , 'noida' , 3 ,2 , 'active', '2019-01-14'),
  31. ('shishir' , 'A-40, noida, UP' , 'noida' , 3 ,3, 'active', '2019-01-14'),
  32. ('rahul' , 'A-41, noida, UP' , 'delhi' , 1 ,2, 'active', '2019-01-14'),
  33. ('mohit' , 'A-42, noida, UP' , 'delhi' , 2 ,1, 'active', '2019-01-14'),
  34. ('karan' , 'A-43, noida, UP' , 'noida' , 1 ,3, 'active', '2019-01-14'),
  35. ('kapil' , 'A-44, noida, UP' , 'noida' , null ,1, 'active', '2019-01-14');
  36.  
  37.  
  38.  
  39.  
  40.  
  41. insert into company values ('CTT', 'noida'),
  42. ('HWT', 'delhi');
  43.  
  44.  
  45.  
  46.  
  47. insert into works values (1, 3, 1, 100000),
  48. (1, 4, 1, 100000),
  49. (1, 5, 1, 100000),
  50. (1, 7, 1, 200000),
  51. (1, 6, 2, 100000),
  52. (1, 8, 2, 100000);
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. --Create Non-Clustered index
  60. create NonClustered index workIndex
  61. on works(empId, cmpId);
  62.  
  63.  
  64.  
  65. --Create Clustered index
  66. create NonClustered index idWork
  67. on works(workId);
  68.  
  69.  
  70. select * into work_backup from works;
  71.  
  72. --Filtered non clustered
  73. create NonClustered index backupWorks
  74. on work_backup(sal) where sal>40000;
Add Comment
Please, Sign In to add comment