Advertisement
Guest User

bazka

a guest
Jan 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.71 KB | None | 0 0
  1. /*==============================================================*/
  2. /* DBMS name: Microsoft SQL Server 2014 */
  3. /* Created on: 09.12.2017 19:38:06 */
  4. /*==============================================================*/
  5.  
  6.  
  7. if exists (select 1
  8. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  9. where r.fkeyid = object_id('Bilet') and o.name = 'FK_BILET_RODZAJU_RODZAJ')
  10. alter table Bilet
  11. drop constraint FK_BILET_RODZAJU_RODZAJ
  12. go
  13.  
  14. if exists (select 1
  15. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  16. where r.fkeyid = object_id('"Jest na trasie"') and o.name = 'FK_JEST NA _JEST NA T_TRASA')
  17. alter table "Jest na trasie"
  18. drop constraint "FK_JEST NA _JEST NA T_TRASA"
  19. go
  20.  
  21. if exists (select 1
  22. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  23. where r.fkeyid = object_id('"Jest na trasie"') and o.name = 'FK_JEST NA _JEST NA T_PRZYSTAN')
  24. alter table "Jest na trasie"
  25. drop constraint "FK_JEST NA _JEST NA T_PRZYSTAN"
  26. go
  27.  
  28. if exists (select 1
  29. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  30. where r.fkeyid = object_id('"Jest przypisana do"') and o.name = 'FK_JEST PRZ_JEST PRZY_KURS')
  31. alter table "Jest przypisana do"
  32. drop constraint "FK_JEST PRZ_JEST PRZY_KURS"
  33. go
  34.  
  35. if exists (select 1
  36. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  37. where r.fkeyid = object_id('"Jest przypisana do"') and o.name = 'FK_JEST PRZ_JEST PRZY_TRASA')
  38. alter table "Jest przypisana do"
  39. drop constraint "FK_JEST PRZ_JEST PRZY_TRASA"
  40. go
  41.  
  42. if exists (select 1
  43. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  44. where r.fkeyid = object_id('Kierunek') and o.name = 'FK_KIERUNEK_KOŃCZY W_MIEJSCOW')
  45. alter table Kierunek
  46. drop constraint "FK_KIERUNEK_KOŃCZY W_MIEJSCOW"
  47. go
  48.  
  49. if exists (select 1
  50. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  51. where r.fkeyid = object_id('Kierunek') and o.name = 'FK_KIERUNEK_STARTUJE _MIEJSCOW')
  52. alter table Kierunek
  53. drop constraint "FK_KIERUNEK_STARTUJE _MIEJSCOW"
  54. go
  55.  
  56. if exists (select 1
  57. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  58. where r.fkeyid = object_id('Kurs') and o.name = 'FK_KURS_JEST KIER_KIEROWCA')
  59. alter table Kurs
  60. drop constraint "FK_KURS_JEST KIER_KIEROWCA"
  61. go
  62.  
  63. if exists (select 1
  64. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  65. where r.fkeyid = object_id('Kurs') and o.name = 'FK_KURS_RELATIONS_KIERUNEK')
  66. alter table Kurs
  67. drop constraint FK_KURS_RELATIONS_KIERUNEK
  68. go
  69.  
  70. if exists (select 1
  71. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  72. where r.fkeyid = object_id('Kurs') and o.name = 'FK_KURS_JEST UZYW_AUTOKAR')
  73. alter table Kurs
  74. drop constraint "FK_KURS_JEST UZYW_AUTOKAR"
  75. go
  76.  
  77. if exists (select 1
  78. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  79. where r.fkeyid = object_id('Pasazer') and o.name = 'FK_PASAZER_BYL PASAR_KURS')
  80. alter table Pasazer
  81. drop constraint "FK_PASAZER_BYL PASAR_KURS"
  82. go
  83.  
  84. if exists (select 1
  85. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  86. where r.fkeyid = object_id('Pasazer') and o.name = 'FK_PASAZER_KUPIONY P_BILET')
  87. alter table Pasazer
  88. drop constraint "FK_PASAZER_KUPIONY P_BILET"
  89. go
  90.  
  91. if exists (select 1
  92. from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
  93. where r.fkeyid = object_id('Przystanek') and o.name = 'FK_PRZYSTAN_TO JEST_MIEJSCOW')
  94. alter table Przystanek
  95. drop constraint "FK_PRZYSTAN_TO JEST_MIEJSCOW"
  96. go
  97.  
  98. if exists (select 1
  99. from sysobjects
  100. where id = object_id('Autokar')
  101. and type = 'U')
  102. drop table Autokar
  103. go
  104.  
  105. if exists (select 1
  106. from sysindexes
  107. where id = object_id('Bilet')
  108. and name = 'Rodzaju_FK'
  109. and indid > 0
  110. and indid < 255)
  111. drop index Bilet.Rodzaju_FK
  112. go
  113.  
  114. if exists (select 1
  115. from sysobjects
  116. where id = object_id('Bilet')
  117. and type = 'U')
  118. drop table Bilet
  119. go
  120.  
  121. if exists (select 1
  122. from sysindexes
  123. where id = object_id('"Jest na trasie"')
  124. and name = 'Jest na trasie2_FK'
  125. and indid > 0
  126. and indid < 255)
  127. drop index "Jest na trasie"."Jest na trasie2_FK"
  128. go
  129.  
  130. if exists (select 1
  131. from sysindexes
  132. where id = object_id('"Jest na trasie"')
  133. and name = 'Jest na trasie_FK'
  134. and indid > 0
  135. and indid < 255)
  136. drop index "Jest na trasie"."Jest na trasie_FK"
  137. go
  138.  
  139. if exists (select 1
  140. from sysobjects
  141. where id = object_id('"Jest na trasie"')
  142. and type = 'U')
  143. drop table "Jest na trasie"
  144. go
  145.  
  146. if exists (select 1
  147. from sysindexes
  148. where id = object_id('"Jest przypisana do"')
  149. and name = 'Jest przypisana do2_FK'
  150. and indid > 0
  151. and indid < 255)
  152. drop index "Jest przypisana do"."Jest przypisana do2_FK"
  153. go
  154.  
  155. if exists (select 1
  156. from sysindexes
  157. where id = object_id('"Jest przypisana do"')
  158. and name = 'Jest przypisana do_FK'
  159. and indid > 0
  160. and indid < 255)
  161. drop index "Jest przypisana do"."Jest przypisana do_FK"
  162. go
  163.  
  164. if exists (select 1
  165. from sysobjects
  166. where id = object_id('"Jest przypisana do"')
  167. and type = 'U')
  168. drop table "Jest przypisana do"
  169. go
  170.  
  171. if exists (select 1
  172. from sysobjects
  173. where id = object_id('Kierowca')
  174. and type = 'U')
  175. drop table Kierowca
  176. go
  177.  
  178. if exists (select 1
  179. from sysindexes
  180. where id = object_id('Kierunek')
  181. and name = 'Kończy w_FK'
  182. and indid > 0
  183. and indid < 255)
  184. drop index Kierunek."Kończy w_FK"
  185. go
  186.  
  187. if exists (select 1
  188. from sysindexes
  189. where id = object_id('Kierunek')
  190. and name = 'Startuje z_FK'
  191. and indid > 0
  192. and indid < 255)
  193. drop index Kierunek."Startuje z_FK"
  194. go
  195.  
  196. if exists (select 1
  197. from sysobjects
  198. where id = object_id('Kierunek')
  199. and type = 'U')
  200. drop table Kierunek
  201. go
  202.  
  203. if exists (select 1
  204. from sysindexes
  205. where id = object_id('Kurs')
  206. and name = 'Relationship_8_FK'
  207. and indid > 0
  208. and indid < 255)
  209. drop index Kurs.Relationship_8_FK
  210. go
  211.  
  212. if exists (select 1
  213. from sysindexes
  214. where id = object_id('Kurs')
  215. and name = 'jest uzywany na_FK'
  216. and indid > 0
  217. and indid < 255)
  218. drop index Kurs."jest uzywany na_FK"
  219. go
  220.  
  221. if exists (select 1
  222. from sysindexes
  223. where id = object_id('Kurs')
  224. and name = 'Jest kierowca na_FK'
  225. and indid > 0
  226. and indid < 255)
  227. drop index Kurs."Jest kierowca na_FK"
  228. go
  229.  
  230. if exists (select 1
  231. from sysobjects
  232. where id = object_id('Kurs')
  233. and type = 'U')
  234. drop table Kurs
  235. go
  236.  
  237. if exists (select 1
  238. from sysobjects
  239. where id = object_id('Miejscowosc')
  240. and type = 'U')
  241. drop table Miejscowosc
  242. go
  243.  
  244. if exists (select 1
  245. from sysindexes
  246. where id = object_id('Pasazer')
  247. and name = 'Byl pasarzerem kursu_FK'
  248. and indid > 0
  249. and indid < 255)
  250. drop index Pasazer."Byl pasarzerem kursu_FK"
  251. go
  252.  
  253. if exists (select 1
  254. from sysindexes
  255. where id = object_id('Pasazer')
  256. and name = 'Kupiony przez_FK'
  257. and indid > 0
  258. and indid < 255)
  259. drop index Pasazer."Kupiony przez_FK"
  260. go
  261.  
  262. if exists (select 1
  263. from sysobjects
  264. where id = object_id('Pasazer')
  265. and type = 'U')
  266. drop table Pasazer
  267. go
  268.  
  269. if exists (select 1
  270. from sysindexes
  271. where id = object_id('Przystanek')
  272. and name = 'To jest_FK'
  273. and indid > 0
  274. and indid < 255)
  275. drop index Przystanek."To jest_FK"
  276. go
  277.  
  278. if exists (select 1
  279. from sysobjects
  280. where id = object_id('Przystanek')
  281. and type = 'U')
  282. drop table Przystanek
  283. go
  284.  
  285. if exists (select 1
  286. from sysobjects
  287. where id = object_id('Rodzaj')
  288. and type = 'U')
  289. drop table Rodzaj
  290. go
  291.  
  292. if exists (select 1
  293. from sysobjects
  294. where id = object_id('Trasa')
  295. and type = 'U')
  296. drop table Trasa
  297. go
  298.  
  299. /*==============================================================*/
  300. /* Table: Autokar */
  301. /*==============================================================*/
  302. create table Autokar (
  303. Autobus_ID numeric not null,
  304. Model char(15) null,
  305. Marka char(15) null,
  306. Rejestracja char(10) null,
  307. constraint PK_AUTOKAR primary key (Autobus_ID)
  308. )
  309. go
  310.  
  311. /*==============================================================*/
  312. /* Table: Bilet */
  313. /*==============================================================*/
  314. create table Bilet (
  315. Bilet_ID numeric not null,
  316. NazwaBiletu char(15) not null,
  317. constraint PK_BILET primary key (Bilet_ID)
  318. )
  319. go
  320.  
  321. /*==============================================================*/
  322. /* Index: Rodzaju_FK */
  323. /*==============================================================*/
  324.  
  325.  
  326.  
  327.  
  328. create nonclustered index Rodzaju_FK on Bilet (NazwaBiletu ASC)
  329. go
  330.  
  331. /*==============================================================*/
  332. /* Table: "Jest na trasie" */
  333. /*==============================================================*/
  334. create table "Jest na trasie" (
  335. Trasa_ID numeric not null,
  336. Przystanek_ID numeric not null,
  337. constraint "PK_JEST NA TRASIE" primary key (Trasa_ID, Przystanek_ID)
  338. )
  339. go
  340.  
  341. /*==============================================================*/
  342. /* Index: "Jest na trasie_FK" */
  343. /*==============================================================*/
  344.  
  345.  
  346.  
  347.  
  348. create nonclustered index "Jest na trasie_FK" on "Jest na trasie" (Trasa_ID ASC)
  349. go
  350.  
  351. /*==============================================================*/
  352. /* Index: "Jest na trasie2_FK" */
  353. /*==============================================================*/
  354.  
  355.  
  356.  
  357.  
  358. create nonclustered index "Jest na trasie2_FK" on "Jest na trasie" (Przystanek_ID ASC)
  359. go
  360.  
  361. /*==============================================================*/
  362. /* Table: "Jest przypisana do" */
  363. /*==============================================================*/
  364. create table "Jest przypisana do" (
  365. Kurs_ID numeric not null,
  366. Trasa_ID numeric not null,
  367. constraint "PK_JEST PRZYPISANA DO" primary key (Kurs_ID, Trasa_ID)
  368. )
  369. go
  370.  
  371. /*==============================================================*/
  372. /* Index: "Jest przypisana do_FK" */
  373. /*==============================================================*/
  374.  
  375.  
  376.  
  377.  
  378. create nonclustered index "Jest przypisana do_FK" on "Jest przypisana do" (Kurs_ID ASC)
  379. go
  380.  
  381. /*==============================================================*/
  382. /* Index: "Jest przypisana do2_FK" */
  383. /*==============================================================*/
  384.  
  385.  
  386.  
  387.  
  388. create nonclustered index "Jest przypisana do2_FK" on "Jest przypisana do" (Trasa_ID ASC)
  389. go
  390.  
  391. /*==============================================================*/
  392. /* Table: Kierowca */
  393. /*==============================================================*/
  394. create table Kierowca (
  395. Kierowca_ID numeric not null,
  396. Imie char(15) null,
  397. Nazwisko char(15) null,
  398. DataZatrudnienia datetime null,
  399. constraint PK_KIEROWCA primary key (Kierowca_ID)
  400. )
  401. go
  402.  
  403. /*==============================================================*/
  404. /* Table: Kierunek */
  405. /*==============================================================*/
  406. create table Kierunek (
  407. Kierunek_ID numeric not null,
  408. NazwaMiasta char(20) not null,
  409. Mie_NazwaMiasta char(20) not null,
  410. constraint PK_KIERUNEK primary key (Kierunek_ID)
  411. )
  412. go
  413.  
  414. /*==============================================================*/
  415. /* Index: "Startuje z_FK" */
  416. /*==============================================================*/
  417.  
  418.  
  419.  
  420.  
  421. create nonclustered index "Startuje z_FK" on Kierunek (Mie_NazwaMiasta ASC)
  422. go
  423.  
  424. /*==============================================================*/
  425. /* Index: "Kończy w_FK" */
  426. /*==============================================================*/
  427.  
  428.  
  429.  
  430.  
  431. create nonclustered index "Kończy w_FK" on Kierunek (NazwaMiasta ASC)
  432. go
  433.  
  434. /*==============================================================*/
  435. /* Table: Kurs */
  436. /*==============================================================*/
  437. create table Kurs (
  438. Kurs_ID numeric not null,
  439. Kierowca_ID numeric not null,
  440. Kierunek_ID numeric not null,
  441. Autobus_ID numeric not null,
  442. Data datetime null,
  443. Odjazd datetime null,
  444. Przyjazd datetime null,
  445. constraint PK_KURS primary key (Kurs_ID)
  446. )
  447. go
  448.  
  449. /*==============================================================*/
  450. /* Index: "Jest kierowca na_FK" */
  451. /*==============================================================*/
  452.  
  453.  
  454.  
  455.  
  456. create nonclustered index "Jest kierowca na_FK" on Kurs (Kierowca_ID ASC)
  457. go
  458.  
  459. /*==============================================================*/
  460. /* Index: "jest uzywany na_FK" */
  461. /*==============================================================*/
  462.  
  463.  
  464.  
  465.  
  466. create nonclustered index "jest uzywany na_FK" on Kurs (Autobus_ID ASC)
  467. go
  468.  
  469. /*==============================================================*/
  470. /* Index: Relationship_8_FK */
  471. /*==============================================================*/
  472.  
  473.  
  474.  
  475.  
  476. create nonclustered index Relationship_8_FK on Kurs (Kierunek_ID ASC)
  477. go
  478.  
  479. /*==============================================================*/
  480. /* Table: Miejscowosc */
  481. /*==============================================================*/
  482. create table Miejscowosc (
  483. NazwaMiasta char(20) not null,
  484. constraint PK_MIEJSCOWOSC primary key (NazwaMiasta)
  485. )
  486. go
  487.  
  488. /*==============================================================*/
  489. /* Table: Pasazer */
  490. /*==============================================================*/
  491. create table Pasazer (
  492. Pasazer_ID numeric not null,
  493. Kurs_ID numeric not null,
  494. Bilet_ID numeric not null,
  495. constraint PK_PASAZER primary key (Pasazer_ID)
  496. )
  497. go
  498.  
  499. /*==============================================================*/
  500. /* Index: "Kupiony przez_FK" */
  501. /*==============================================================*/
  502.  
  503.  
  504.  
  505.  
  506. create nonclustered index "Kupiony przez_FK" on Pasazer (Bilet_ID ASC)
  507. go
  508.  
  509. /*==============================================================*/
  510. /* Index: "Byl pasarzerem kursu_FK" */
  511. /*==============================================================*/
  512.  
  513.  
  514.  
  515.  
  516. create nonclustered index "Byl pasarzerem kursu_FK" on Pasazer (Kurs_ID ASC)
  517. go
  518.  
  519. /*==============================================================*/
  520. /* Table: Przystanek */
  521. /*==============================================================*/
  522. create table Przystanek (
  523. Przystanek_ID numeric not null,
  524. NazwaMiasta char(20) not null,
  525. constraint PK_PRZYSTANEK primary key (Przystanek_ID)
  526. )
  527. go
  528.  
  529. /*==============================================================*/
  530. /* Index: "To jest_FK" */
  531. /*==============================================================*/
  532.  
  533.  
  534.  
  535.  
  536. create nonclustered index "To jest_FK" on Przystanek (NazwaMiasta ASC)
  537. go
  538.  
  539. /*==============================================================*/
  540. /* Table: Rodzaj */
  541. /*==============================================================*/
  542. create table Rodzaj (
  543. NazwaBiletu char(15) not null,
  544. constraint PK_RODZAJ primary key (NazwaBiletu)
  545. )
  546. go
  547.  
  548. /*==============================================================*/
  549. /* Table: Trasa */
  550. /*==============================================================*/
  551. create table Trasa (
  552. Trasa_ID numeric not null,
  553. constraint PK_TRASA primary key (Trasa_ID)
  554. )
  555. go
  556.  
  557. alter table Bilet
  558. add constraint FK_BILET_RODZAJU_RODZAJ foreign key (NazwaBiletu)
  559. references Rodzaj (NazwaBiletu)
  560. go
  561.  
  562. alter table "Jest na trasie"
  563. add constraint "FK_JEST NA _JEST NA T_TRASA" foreign key (Trasa_ID)
  564. references Trasa (Trasa_ID)
  565. go
  566.  
  567. alter table "Jest na trasie"
  568. add constraint "FK_JEST NA _JEST NA T_PRZYSTAN" foreign key (Przystanek_ID)
  569. references Przystanek (Przystanek_ID)
  570. go
  571.  
  572. alter table "Jest przypisana do"
  573. add constraint "FK_JEST PRZ_JEST PRZY_KURS" foreign key (Kurs_ID)
  574. references Kurs (Kurs_ID)
  575. go
  576.  
  577. alter table "Jest przypisana do"
  578. add constraint "FK_JEST PRZ_JEST PRZY_TRASA" foreign key (Trasa_ID)
  579. references Trasa (Trasa_ID)
  580. go
  581.  
  582. alter table Kierunek
  583. add constraint "FK_KIERUNEK_KOŃCZY W_MIEJSCOW" foreign key (NazwaMiasta)
  584. references Miejscowosc (NazwaMiasta)
  585. go
  586.  
  587. alter table Kierunek
  588. add constraint "FK_KIERUNEK_STARTUJE _MIEJSCOW" foreign key (Mie_NazwaMiasta)
  589. references Miejscowosc (NazwaMiasta)
  590. go
  591.  
  592. alter table Kurs
  593. add constraint "FK_KURS_JEST KIER_KIEROWCA" foreign key (Kierowca_ID)
  594. references Kierowca (Kierowca_ID)
  595. go
  596.  
  597. alter table Kurs
  598. add constraint FK_KURS_RELATIONS_KIERUNEK foreign key (Kierunek_ID)
  599. references Kierunek (Kierunek_ID)
  600. go
  601.  
  602. alter table Kurs
  603. add constraint "FK_KURS_JEST UZYW_AUTOKAR" foreign key (Autobus_ID)
  604. references Autokar (Autobus_ID)
  605. go
  606.  
  607. alter table Pasazer
  608. add constraint "FK_PASAZER_BYL PASAR_KURS" foreign key (Kurs_ID)
  609. references Kurs (Kurs_ID)
  610. go
  611.  
  612. alter table Pasazer
  613. add constraint "FK_PASAZER_KUPIONY P_BILET" foreign key (Bilet_ID)
  614. references Bilet (Bilet_ID)
  615. go
  616.  
  617. alter table Przystanek
  618. add constraint "FK_PRZYSTAN_TO JEST_MIEJSCOW" foreign key (NazwaMiasta)
  619. references Miejscowosc (NazwaMiasta)
  620. go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement