Создание таблиц.sql 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. use [41П_МДК01.01_Сергеев]
  2. CREATE TABLE Positions
  3. (
  4. Id_position INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  5. Position NVARCHAR(50) NOT NULL
  6. )
  7. CREATE TABLE Roles
  8. (
  9. Id_role INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  10. Role_name NVARCHAR(20) NOT NULL
  11. )
  12. CREATE TABLE Genders
  13. (
  14. Id_gender INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  15. Gender NVARCHAR(10) NOT NULL
  16. )
  17. CREATE TABLE Employees
  18. (
  19. Id_employee INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  20. Surname NVARCHAR(50) NOT NULL,
  21. Names NVARCHAR(50) NOT NULL,
  22. Patronymic NVARCHAR(50) DEFAULT 'Отсутствует' NOT NULL,
  23. Birthdate DATE NOT NULL,
  24. Id_gender INT FOREIGN KEY REFERENCES Genders (Id_gender) NOT NULL,
  25. Id_position INT FOREIGN KEY REFERENCES Positions (Id_position) NOT NULL,
  26. Street NVARCHAR(50) NOT NULL,
  27. Building NVARCHAR(10) NOT NULL,
  28. Phone NVARCHAR(20) NOT NULL,
  29. Login_user NVARCHAR(20) NOT NULL,
  30. Password_user int NOT NULL,
  31. Id_role INT FOREIGN KEY REFERENCES Roles (Id_role) NOT NULL,
  32. )
  33. CREATE TABLE Types_group
  34. (
  35. Id_type INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  36. Type_group NVARCHAR(50) NOT NULL
  37. )
  38. CREATE TABLE Groups
  39. (
  40. Id_group INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  41. Id_type INT FOREIGN KEY REFERENCES Types_group (Id_type) NOT NULL,
  42. Code INT NOT NULL
  43. )
  44. CREATE TABLE Distributions
  45. (
  46. Id_distribution INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  47. Id_employee INT FOREIGN KEY REFERENCES Employees (Id_employee) NOT NULL,
  48. Id_group INT FOREIGN KEY REFERENCES Groups (Id_group) NOT NULL
  49. )
  50. CREATE TABLE Parents
  51. (
  52. Id_parent INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  53. Surname NVARCHAR(50) NOT NULL,
  54. Names NVARCHAR(50) NOT NULL,
  55. Patronymic NVARCHAR(50) DEFAULT 'Отсутствует' NOT NULL,
  56. Birthdate DATE NOT NULL,
  57. Id_gender INT FOREIGN KEY REFERENCES Genders (Id_gender) NOT NULL,
  58. Street NVARCHAR(50) NOT NULL,
  59. Building NVARCHAR(10) NOT NULL,
  60. Phone NVARCHAR(20) NOT NULL
  61. )
  62. CREATE TABLE Sertificates
  63. (
  64. Id_sertificate INT PRIMARY KEY FOREIGN KEY REFERENCES Children (Id_child) NOT NULL,
  65. Series NVARCHAR(10) NOT NULL,
  66. Number INT NOT NULL,
  67. Date_issue DATE NOT NULL,
  68. Iddued NVARCHAR(100) NOT NULL
  69. )
  70. CREATE TABLE Children
  71. (
  72. Id_child INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  73. Surname NVARCHAR(50) NOT NULL,
  74. Names NVARCHAR(50) NOT NULL,
  75. Patronymic NVARCHAR(50) DEFAULT 'Отсутствует' NOT NULL,
  76. Birthdate DATE NOT NULL,
  77. Id_gender INT FOREIGN KEY REFERENCES Genders (Id_gender) NOT NULL,
  78. Id_group INT FOREIGN KEY REFERENCES Groups (Id_group) NOT NULL,
  79. Street NVARCHAR(50) NOT NULL,
  80. Building NVARCHAR(10) NOT NULL,
  81. Photo NVARCHAR(100)
  82. )
  83. CREATE TABLE Attendance
  84. (
  85. Id_visit INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  86. Date_visit DATE NOT NULL,
  87. Id_child INT FOREIGN KEY REFERENCES Children (Id_child) NOT NULL,
  88. Status_visit INT DEFAULT 1 NOT NULL
  89. )
  90. CREATE TABLE Kinships
  91. (
  92. Id_kinship INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  93. Id_parent INT FOREIGN KEY REFERENCES Parents (Id_parent) NOT NULL,
  94. Id_child INT FOREIGN KEY REFERENCES Children (Id_child) NOT NULL
  95. )
  96. CREATE TABLE Photos
  97. (
  98. Id_photo INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
  99. Id_employee INT FOREIGN KEY REFERENCES Employees (Id_employee) ON DELETE CASCADE,
  100. Id_children INT FOREIGN KEY REFERENCES Children (Id_child) ON DELETE CASCADE,
  101. Byte_photo VARBINARY(MAX),
  102. Path_photo NVARCHAR(200)
  103. )