daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Dec 11th, 2017 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ujeb.se/pppooo
  2.  
  3. SET ANSI_NULLS ON
  4. GO
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Klienci]') AND TYPE IN (N'U'))
  8. BEGIN
  9. CREATE TABLE [dbo].[Klienci](
  10.     [Id] [INT] IDENTITY(1,1) NOT NULL,
  11.     [Klient] [VARCHAR](50) NULL,
  12.  CONSTRAINT [PK_Klienci] PRIMARY KEY CLUSTERED
  13. (
  14.     [Id] ASC
  15. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  16. ) ON [PRIMARY]
  17. END
  18. GO
  19. SET ANSI_NULLS ON
  20. GO
  21. SET QUOTED_IDENTIFIER ON
  22. GO
  23. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Czas]') AND TYPE IN (N'U'))
  24. BEGIN
  25. CREATE TABLE [dbo].[Czas](
  26.     [Id] [INT] IDENTITY(1,1) NOT NULL,
  27.     [Miesiac] [INT] NULL,
  28.     [Kwartal] [INT] NULL,
  29.     [Rok] [INT] NULL,
  30.     [DATA] [CHAR](7) NULL,
  31.  CONSTRAINT [PK_Czas] PRIMARY KEY CLUSTERED
  32. (
  33.     [Id] ASC
  34. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  35. ) ON [PRIMARY]
  36. END
  37. GO
  38. SET ANSI_NULLS ON
  39. GO
  40. SET QUOTED_IDENTIFIER ON
  41. GO
  42. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Regiony]') AND TYPE IN (N'U'))
  43. BEGIN
  44. CREATE TABLE [dbo].[Regiony](
  45.     [Id] [INT] IDENTITY(1,1) NOT NULL,
  46.     [Region] [VARCHAR](20) NULL,
  47.  CONSTRAINT [PK_Regiony] PRIMARY KEY CLUSTERED
  48. (
  49.     [Id] ASC
  50. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  51. ) ON [PRIMARY]
  52. END
  53. GO
  54. SET ANSI_NULLS ON
  55. GO
  56. SET QUOTED_IDENTIFIER ON
  57. GO
  58. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Towary]') AND TYPE IN (N'U'))
  59. BEGIN
  60. CREATE TABLE [dbo].[Towary](
  61.     [Id] [INT] IDENTITY(1,1) NOT NULL,
  62.     [Sprzet] [VARCHAR](40) NULL,
  63.     [Podgrupa] [VARCHAR](40) NULL,
  64.     [Grupa] [CHAR](2) NULL,
  65.  CONSTRAINT [PK_Towary] PRIMARY KEY CLUSTERED
  66. (
  67.     [Id] ASC
  68. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  69. ) ON [PRIMARY]
  70. END
  71. GO
  72. SET ANSI_NULLS ON
  73. GO
  74. SET QUOTED_IDENTIFIER ON
  75. GO
  76. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sprzedaz_plan]') AND TYPE IN (N'U'))
  77. BEGIN
  78. CREATE TABLE [dbo].[Sprzedaz_plan](
  79.     [Cena] [money] NULL,
  80.     [Ilosc] [money] NULL,
  81.     [Obrot] [money] NULL,
  82.     [Klient_Id] [INT] NOT NULL,
  83.     [Region_Id] [INT] NOT NULL,
  84.     [Towary_Id] [INT] NOT NULL,
  85.     [Czas_Id] [INT] NOT NULL,
  86.  CONSTRAINT [PK__Sprzedaz_plan__1B0907CE] PRIMARY KEY CLUSTERED
  87. (
  88.     [Klient_Id] ASC,
  89.     [Region_Id] ASC,
  90.     [Towary_Id] ASC,
  91.     [Czas_Id] ASC
  92. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  93. ) ON [PRIMARY]
  94. END
  95. GO
  96. SET ANSI_NULLS ON
  97. GO
  98. SET QUOTED_IDENTIFIER ON
  99. GO
  100. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sprzedaz_hist]') AND TYPE IN (N'U'))
  101. BEGIN
  102. CREATE TABLE [dbo].[Sprzedaz_hist](
  103.     [Cena] [money] NULL,
  104.     [Ilosc] [money] NULL,
  105.     [Obrot] [money] NULL,
  106.     [Klient_Id] [INT] NOT NULL,
  107.     [Region_Id] [INT] NOT NULL,
  108.     [Towary_Id] [INT] NOT NULL,
  109.     [Czas_Id] [INT] NOT NULL,
  110.  CONSTRAINT [PK__Sprzedaz_hist__1BFD2C07] PRIMARY KEY CLUSTERED
  111. (
  112.     [Klient_Id] ASC,
  113.     [Region_Id] ASC,
  114.     [Towary_Id] ASC,
  115.     [Czas_Id] ASC
  116. )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
  117. ) ON [PRIMARY]
  118. END
  119. GO
  120. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_plan_Czas]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_plan]'))
  121. ALTER TABLE [dbo].[Sprzedaz_plan]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_plan_Czas] FOREIGN KEY([Czas_Id])
  122. REFERENCES [dbo].[Czas] ([Id])
  123. GO
  124. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_plan_Klienci]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_plan]'))
  125. ALTER TABLE [dbo].[Sprzedaz_plan]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_plan_Klienci] FOREIGN KEY([Klient_Id])
  126. REFERENCES [dbo].[Klienci] ([Id])
  127. GO
  128. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_plan_Regiony]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_plan]'))
  129. ALTER TABLE [dbo].[Sprzedaz_plan]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_plan_Regiony] FOREIGN KEY([Region_Id])
  130. REFERENCES [dbo].[Regiony] ([Id])
  131. GO
  132. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_plan_Towary]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_plan]'))
  133. ALTER TABLE [dbo].[Sprzedaz_plan]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_plan_Towary] FOREIGN KEY([Towary_Id])
  134. REFERENCES [dbo].[Towary] ([Id])
  135. GO
  136. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_hist_Czas]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_hist]'))
  137. ALTER TABLE [dbo].[Sprzedaz_hist]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_hist_Czas] FOREIGN KEY([Czas_Id])
  138. REFERENCES [dbo].[Czas] ([Id])
  139. GO
  140. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_hist_Klienci]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_hist]'))
  141. ALTER TABLE [dbo].[Sprzedaz_hist]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_hist_Klienci] FOREIGN KEY([Klient_Id])
  142. REFERENCES [dbo].[Klienci] ([Id])
  143. GO
  144. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_hist_Regiony]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_hist]'))
  145. ALTER TABLE [dbo].[Sprzedaz_hist]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_hist_Regiony] FOREIGN KEY([Region_Id])
  146. REFERENCES [dbo].[Regiony] ([Id])
  147. GO
  148. IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Sprzedaz_hist_Towary]') AND parent_object_id = OBJECT_ID(N'[dbo].[Sprzedaz_hist]'))
  149. ALTER TABLE [dbo].[Sprzedaz_hist]  WITH CHECK ADD  CONSTRAINT [FK_Sprzedaz_hist_Towary] FOREIGN KEY([Towary_Id])
  150. REFERENCES [dbo].[Towary] ([Id])
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