Advertisement
Guest User

Zadanie #1, Bazy Danych, 28.05.2015 r.

a guest
May 28th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.27 KB | None | 0 0
  1. --1a)
  2. create table LeaveTypes(
  3. LeaveTypeID int not null,
  4. Name varchar(15) not null,
  5. IsPaid bit not null
  6.  
  7. primary key (LeaveTypeID));
  8.  
  9. create table Leaves(
  10. LeaveID int not null,
  11. EmployeeID int not null,
  12. FirstDay date not null,
  13. LastDay date null,
  14. LeaveTypeID int not null,
  15. DeputyEmployeeID int null,
  16. AvailableByPhone bit not null,
  17. PaidPercent real null
  18.  
  19. primary key (LeaveID)
  20. foreign key (EmployeeID) references Employees(EmployeeID),
  21. foreign key (LeaveTypeID) references LeaveTypes(LeaveTypeID),
  22. foreign key (DeputyEmployeeID) references Employees(EmployeeID));
  23.  
  24. --1b)
  25. alter table Employees
  26. add HolidayLeaveDaysRemains smallint;
  27.  
  28. --1c)
  29. alter table LeaveTypes
  30. alter column Name varchar(20);
  31.  
  32. --1d)
  33. insert into LeaveTypes
  34. (LeaveTypeID, Name, IsPaid)
  35. values(1, 'macierzyński', 1),
  36. (2, 'chorobowy', 1),
  37. (3, 'wypoczynkowy', 0);
  38.  
  39. select * from LeaveTypes;
  40.  
  41. --1e)
  42. insert into Leaves
  43. (LeaveID, EmployeeID, FirstDay, LastDay, LeaveTypeID, AvailableByPhone)
  44. values(1, 1, '2014-05-01', '2014-05-10', 1, 1),
  45. (2, 1, '2015-05-01', '2015-05-10', 1, 0);
  46.  
  47. select e.LastName, e.FirstName, lt.Name from Leaves l
  48. join Employees e on e.EmployeeID = l.EmployeeID
  49. join LeaveTypes lt on lt.LeaveTypeID = l.LeaveTypeID;
  50.  
  51. --1f)
  52. alter table Leaves
  53. drop column AvailableByPhone;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement