Advertisement
altair

GOC335 DDL T-SQL

Apr 2nd, 2011
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 7.68 KB | None | 0 0
  1. -- --------------------------------------------------
  2. -- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
  3. -- --------------------------------------------------
  4. -- Date Created: 04/02/2011 16:00:07
  5. -- Generated from EDMX file: c:\users\developer\documents\visual studio 2010\Projects\NemesisEvents\Altairis.Nemesis.Events.Data\NemesisEvents.edmx
  6. -- --------------------------------------------------
  7.  
  8. SET QUOTED_IDENTIFIER OFF;
  9. GO
  10. USE [NemesisEvents];
  11. GO
  12. IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
  13. GO
  14.  
  15. -- --------------------------------------------------
  16. -- Dropping existing FOREIGN KEY constraints
  17. -- --------------------------------------------------
  18.  
  19. IF OBJECT_ID(N'[dbo].[FK_Events_Users]', 'F') IS NOT NULL
  20.     ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_Events_Users];
  21. GO
  22. IF OBJECT_ID(N'[dbo].[FK_Events_Venues]', 'F') IS NOT NULL
  23.     ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_Events_Venues];
  24. GO
  25. IF OBJECT_ID(N'[dbo].[FK_Venues_Areas]', 'F') IS NOT NULL
  26.     ALTER TABLE [dbo].[Venues] DROP CONSTRAINT [FK_Venues_Areas];
  27. GO
  28.  
  29. -- --------------------------------------------------
  30. -- Dropping existing tables
  31. -- --------------------------------------------------
  32.  
  33. IF OBJECT_ID(N'[dbo].[Areas]', 'U') IS NOT NULL
  34.     DROP TABLE [dbo].[Areas];
  35. GO
  36. IF OBJECT_ID(N'[dbo].[Events]', 'U') IS NOT NULL
  37.     DROP TABLE [dbo].[Events];
  38. GO
  39. IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
  40.     DROP TABLE [dbo].[Users];
  41. GO
  42. IF OBJECT_ID(N'[dbo].[Venues]', 'U') IS NOT NULL
  43.     DROP TABLE [dbo].[Venues];
  44. GO
  45.  
  46. -- --------------------------------------------------
  47. -- Creating all tables
  48. -- --------------------------------------------------
  49.  
  50. -- Creating table 'Areas'
  51. CREATE TABLE [dbo].[Areas] (
  52.     [AreaId] int IDENTITY(1,1) NOT NULL,
  53.     [Name] nvarchar(100)  NOT NULL
  54. );
  55. GO
  56.  
  57. -- Creating table 'Events'
  58. CREATE TABLE [dbo].[Events] (
  59.     [EventId] int IDENTITY(1,1) NOT NULL,
  60.     [Name] nvarchar(100)  NOT NULL,
  61.     [Description] nvarchar(max)  NOT NULL,
  62.     [DateBegin] datetime  NOT NULL,
  63.     [VenueId] int  NOT NULL,
  64.     [OwnerUserName] nvarchar(100)  NOT NULL,
  65.     [UseRegistration] bit  NOT NULL,
  66.     [AllowRegistration] bit  NOT NULL
  67. );
  68. GO
  69.  
  70. -- Creating table 'Users'
  71. CREATE TABLE [dbo].[Users] (
  72.     [UserName] nvarchar(100)  NOT NULL,
  73.     [PasswordHash] binary(64)  NOT NULL,
  74.     [PasswordSalt] binary(128)  NOT NULL,
  75.     [Email] nvarchar(100)  NOT NULL,
  76.     [Comment] nvarchar(max)  NULL,
  77.     [IsApproved] bit  NOT NULL,
  78.     [DateCreated] datetime  NOT NULL,
  79.     [DateLastLogin] datetime  NULL,
  80.     [DateLastActivity] datetime  NULL,
  81.     [DateLastPasswordChange] datetime  NOT NULL,
  82.     [DisplayName] nvarchar(100)  NULL,
  83.     [IsAdministrator] bit  NOT NULL,
  84.     [IsOrganizer] bit  NOT NULL
  85. );
  86. GO
  87.  
  88. -- Creating table 'Venues'
  89. CREATE TABLE [dbo].[Venues] (
  90.     [VenueId] int IDENTITY(1,1) NOT NULL,
  91.     [Name] nvarchar(100)  NOT NULL,
  92.     [StreetAddress] nvarchar(100)  NULL,
  93.     [Description] nvarchar(max)  NULL,
  94.     [AreaId] int  NOT NULL
  95. );
  96. GO
  97.  
  98. -- Creating table 'UsersRegisteredToEvent'
  99. CREATE TABLE [dbo].[UsersRegisteredToEvent] (
  100.     [UsersRegistered_UserName] nvarchar(100)  NOT NULL,
  101.     [EventsRegistered_EventId] int  NOT NULL
  102. );
  103. GO
  104.  
  105. -- Creating table 'UserArea'
  106. CREATE TABLE [dbo].[UserArea] (
  107.     [WatchingUsers_UserName] nvarchar(100)  NOT NULL,
  108.     [WatchedAreas_AreaId] int  NOT NULL
  109. );
  110. GO
  111.  
  112. -- --------------------------------------------------
  113. -- Creating all PRIMARY KEY constraints
  114. -- --------------------------------------------------
  115.  
  116. -- Creating primary key on [AreaId] in table 'Areas'
  117. ALTER TABLE [dbo].[Areas]
  118. ADD CONSTRAINT [PK_Areas]
  119.     PRIMARY KEY CLUSTERED ([AreaId] ASC);
  120. GO
  121.  
  122. -- Creating primary key on [EventId] in table 'Events'
  123. ALTER TABLE [dbo].[Events]
  124. ADD CONSTRAINT [PK_Events]
  125.     PRIMARY KEY CLUSTERED ([EventId] ASC);
  126. GO
  127.  
  128. -- Creating primary key on [UserName] in table 'Users'
  129. ALTER TABLE [dbo].[Users]
  130. ADD CONSTRAINT [PK_Users]
  131.     PRIMARY KEY CLUSTERED ([UserName] ASC);
  132. GO
  133.  
  134. -- Creating primary key on [VenueId] in table 'Venues'
  135. ALTER TABLE [dbo].[Venues]
  136. ADD CONSTRAINT [PK_Venues]
  137.     PRIMARY KEY CLUSTERED ([VenueId] ASC);
  138. GO
  139.  
  140. -- Creating primary key on [UsersRegistered_UserName], [EventsRegistered_EventId] in table 'UsersRegisteredToEvent'
  141. ALTER TABLE [dbo].[UsersRegisteredToEvent]
  142. ADD CONSTRAINT [PK_UsersRegisteredToEvent]
  143.     PRIMARY KEY NONCLUSTERED ([UsersRegistered_UserName], [EventsRegistered_EventId] ASC);
  144. GO
  145.  
  146. -- Creating primary key on [WatchingUsers_UserName], [WatchedAreas_AreaId] in table 'UserArea'
  147. ALTER TABLE [dbo].[UserArea]
  148. ADD CONSTRAINT [PK_UserArea]
  149.     PRIMARY KEY NONCLUSTERED ([WatchingUsers_UserName], [WatchedAreas_AreaId] ASC);
  150. GO
  151.  
  152. -- --------------------------------------------------
  153. -- Creating all FOREIGN KEY constraints
  154. -- --------------------------------------------------
  155.  
  156. -- Creating foreign key on [AreaId] in table 'Venues'
  157. ALTER TABLE [dbo].[Venues]
  158. ADD CONSTRAINT [FK_Venues_Areas]
  159.     FOREIGN KEY ([AreaId])
  160.     REFERENCES [dbo].[Areas]
  161.         ([AreaId])
  162.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  163.  
  164. -- Creating non-clustered index for FOREIGN KEY 'FK_Venues_Areas'
  165. CREATE INDEX [IX_FK_Venues_Areas]
  166. ON [dbo].[Venues]
  167.     ([AreaId]);
  168. GO
  169.  
  170. -- Creating foreign key on [OwnerUserName] in table 'Events'
  171. ALTER TABLE [dbo].[Events]
  172. ADD CONSTRAINT [FK_Events_Users]
  173.     FOREIGN KEY ([OwnerUserName])
  174.     REFERENCES [dbo].[Users]
  175.         ([UserName])
  176.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  177.  
  178. -- Creating non-clustered index for FOREIGN KEY 'FK_Events_Users'
  179. CREATE INDEX [IX_FK_Events_Users]
  180. ON [dbo].[Events]
  181.     ([OwnerUserName]);
  182. GO
  183.  
  184. -- Creating foreign key on [VenueId] in table 'Events'
  185. ALTER TABLE [dbo].[Events]
  186. ADD CONSTRAINT [FK_Events_Venues]
  187.     FOREIGN KEY ([VenueId])
  188.     REFERENCES [dbo].[Venues]
  189.         ([VenueId])
  190.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  191.  
  192. -- Creating non-clustered index for FOREIGN KEY 'FK_Events_Venues'
  193. CREATE INDEX [IX_FK_Events_Venues]
  194. ON [dbo].[Events]
  195.     ([VenueId]);
  196. GO
  197.  
  198. -- Creating foreign key on [UsersRegistered_UserName] in table 'UsersRegisteredToEvent'
  199. ALTER TABLE [dbo].[UsersRegisteredToEvent]
  200. ADD CONSTRAINT [FK_UsersRegisteredToEvent_User]
  201.     FOREIGN KEY ([UsersRegistered_UserName])
  202.     REFERENCES [dbo].[Users]
  203.         ([UserName])
  204.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  205. GO
  206.  
  207. -- Creating foreign key on [EventsRegistered_EventId] in table 'UsersRegisteredToEvent'
  208. ALTER TABLE [dbo].[UsersRegisteredToEvent]
  209. ADD CONSTRAINT [FK_UsersRegisteredToEvent_Event]
  210.     FOREIGN KEY ([EventsRegistered_EventId])
  211.     REFERENCES [dbo].[Events]
  212.         ([EventId])
  213.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  214.  
  215. -- Creating non-clustered index for FOREIGN KEY 'FK_UsersRegisteredToEvent_Event'
  216. CREATE INDEX [IX_FK_UsersRegisteredToEvent_Event]
  217. ON [dbo].[UsersRegisteredToEvent]
  218.     ([EventsRegistered_EventId]);
  219. GO
  220.  
  221. -- Creating foreign key on [WatchingUsers_UserName] in table 'UserArea'
  222. ALTER TABLE [dbo].[UserArea]
  223. ADD CONSTRAINT [FK_UserArea_User]
  224.     FOREIGN KEY ([WatchingUsers_UserName])
  225.     REFERENCES [dbo].[Users]
  226.         ([UserName])
  227.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  228. GO
  229.  
  230. -- Creating foreign key on [WatchedAreas_AreaId] in table 'UserArea'
  231. ALTER TABLE [dbo].[UserArea]
  232. ADD CONSTRAINT [FK_UserArea_Area]
  233.     FOREIGN KEY ([WatchedAreas_AreaId])
  234.     REFERENCES [dbo].[Areas]
  235.         ([AreaId])
  236.     ON DELETE NO ACTION ON UPDATE NO ACTION;
  237.  
  238. -- Creating non-clustered index for FOREIGN KEY 'FK_UserArea_Area'
  239. CREATE INDEX [IX_FK_UserArea_Area]
  240. ON [dbo].[UserArea]
  241.     ([WatchedAreas_AreaId]);
  242. GO
  243.  
  244. -- --------------------------------------------------
  245. -- Script has ended
  246. -- --------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement