SHARE
TWEET

Untitled

a guest Oct 17th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ---------------------------------------------------- */
  2. /*  Generated by Enterprise Architect Version 14.0      */
  3. /*  Created On : 10-říj-2019 8:23:19              */
  4. /*  DBMS       : SQL Server 2012                        */
  5. /* ---------------------------------------------------- */
  6.  
  7. /* Drop Foreign Key Constraints */
  8.  
  9. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[FK_Garantuje_Ucitel]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  10. ALTER TABLE [Predmet] DROP CONSTRAINT [FK_Garantuje_Ucitel]
  11. GO
  12.  
  13. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[FK_Studuje_Obor]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  14. ALTER TABLE [Student] DROP CONSTRAINT [FK_Studuje_Obor]
  15. GO
  16.  
  17. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[FK_Student_Zapis]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  18. ALTER TABLE [Zapis] DROP CONSTRAINT [FK_Student_Zapis]
  19. GO
  20.  
  21. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[FK_Predmet_Zapis]') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
  22. ALTER TABLE [Zapis] DROP CONSTRAINT [FK_Predmet_Zapis]
  23. GO
  24.  
  25. /* Drop Tables */
  26.  
  27. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[Obor]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  28. DROP TABLE [Obor]
  29. GO
  30.  
  31. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[Predmet]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  32. DROP TABLE [Predmet]
  33. GO
  34.  
  35. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[Student]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  36. DROP TABLE [Student]
  37. GO
  38.  
  39. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[Ucitel]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  40. DROP TABLE [Ucitel]
  41. GO
  42.  
  43. IF EXISTS (SELECT 1 FROM dbo.sysobjects WHERE id = object_id(N'[Zapis]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  44. DROP TABLE [Zapis]
  45. GO
  46.  
  47. /* Create Tables */
  48.  
  49. CREATE TABLE [Obor]
  50. (
  51.     [OborID] int NOT NULL,
  52.     [Nazev] varchar(50) NULL
  53. )
  54. GO
  55.  
  56. CREATE TABLE [Predmet]
  57. (
  58.     [PredmetID] int NOT NULL,
  59.     [Nazev] varchar(50) NULL,
  60.     [Mistnost] varchar(6) NULL,
  61.     [UcitelID] int NULL
  62. )
  63. GO
  64.  
  65. CREATE TABLE [Student]
  66. (
  67.     [StudentID] int NOT NULL,
  68.     [Jmeno] varchar(50) NULL,
  69.     [Prijmeni] varchar(50) NULL,
  70.     [Vek] int NULL,
  71.     [Rocnik] int NULL,
  72.     [OborID] int NULL
  73. )
  74. GO
  75.  
  76. CREATE TABLE [Ucitel]
  77. (
  78.     [UcitelID] int NOT NULL,
  79.     [Jmeno] varchar(50) NULL,
  80.     [Prijmeni] varchar(50) NULL,
  81.     [Titul] varchar(20) NULL
  82. )
  83. GO
  84.  
  85. CREATE TABLE [Zapis]
  86. (
  87.     [Hodnoceni] int NULL,
  88.     [StudentID] int NOT NULL,
  89.     [PredmetID] int NOT NULL
  90. )
  91. GO
  92.  
  93. /* Create Primary Keys, Indexes, Uniques, Checks */
  94.  
  95. ALTER TABLE [Obor]
  96.  ADD CONSTRAINT [PK_Obor]
  97.     PRIMARY KEY CLUSTERED ([OborID] ASC)
  98. GO
  99.  
  100. ALTER TABLE [Predmet]
  101.  ADD CONSTRAINT [PK_Predmet]
  102.     PRIMARY KEY CLUSTERED ([PredmetID] ASC)
  103. GO
  104.  
  105. ALTER TABLE [Student]
  106.  ADD CONSTRAINT [PK_Student]
  107.     PRIMARY KEY CLUSTERED ([StudentID] ASC)
  108. GO
  109.  
  110. ALTER TABLE [Ucitel]
  111.  ADD CONSTRAINT [PK_Ucitel]
  112.     PRIMARY KEY CLUSTERED ([UcitelID] ASC)
  113. GO
  114.  
  115. ALTER TABLE [Zapis]
  116.  ADD CONSTRAINT [PK_Zapis]
  117.     PRIMARY KEY CLUSTERED ([StudentID] ASC,[PredmetID] ASC)
  118. GO
  119.  
  120. /* Create Foreign Key Constraints */
  121.  
  122. ALTER TABLE [Predmet] ADD CONSTRAINT [FK_Garantuje_Ucitel]
  123.     FOREIGN KEY ([UcitelID]) REFERENCES [Ucitel] ([UcitelID]) ON DELETE No Action ON UPDATE No Action
  124. GO
  125.  
  126. ALTER TABLE [Student] ADD CONSTRAINT [FK_Studuje_Obor]
  127.     FOREIGN KEY ([OborID]) REFERENCES [Obor] ([OborID]) ON DELETE No Action ON UPDATE No Action
  128. GO
  129.  
  130. ALTER TABLE [Zapis] ADD CONSTRAINT [FK_Student_Zapis]
  131.     FOREIGN KEY ([StudentID]) REFERENCES [Student] ([StudentID]) ON DELETE No Action ON UPDATE No Action
  132. GO
  133.  
  134. ALTER TABLE [Zapis] ADD CONSTRAINT [FK_Predmet_Zapis]
  135.     FOREIGN KEY ([PredmetID]) REFERENCES [Predmet] ([PredmetID]) ON DELETE No Action ON UPDATE No Action
  136. GO
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top