· 6 years ago · Jun 14, 2019, 10:27 AM
1-- Create a new table called '[Events]' in schema '[dbo]'
2-- Drop the table if it already exists
3DROP TABLE IF EXISTS [dbo].[Events]
4GO
5-- Create the table in the specified schema
6CREATE TABLE [dbo].[Events]
7(
8 [Id] INT NOT NULL PRIMARY KEY IDENTITY, -- Primary Key column
9 [ImportTypeId] INT NULL
10 REFERENCES [dbo].[ImportTypes](Id),
11 [ImportId] NVARCHAR(50) NULL,
12 [Title] NVARCHAR(512) NOT NULL,
13 [Description] NVARCHAR(2048) NOT NULL,
14
15 CONSTRAINT UQ_Events UNIQUE (ImportId, ImportTypeId),
16 INDEX IX_EventTitle ([Title] ASC)
17);
18GO
19
20-- Create a new table called '[Events]' in schema '[eventful]'
21-- Drop the table if it already exists
22DROP TABLE IF EXISTS [eventful].[Events]
23GO
24
25-- Create the table in the specified schema
26CREATE TABLE [eventful].[Events]
27(
28 [EventfulId] NVARCHAR(50) NOT NULL
29 REFERENCES [dbo].[Events](ImportId),
30 [ImportDate] DATETIME NOT NULL DEFAULT(GETUTCDATE()),
31 [LastImportDate] DATETIME NULL,
32 [Url] NVARCHAR(2048) NULL,
33
34 CONSTRAINT PK_EventfulEvents PRIMARY KEY CLUSTERED (EventfulId)
35);
36GO
37
38REFERENCES [dbo].[Events](ImportId)
39
40CONSTRAINT UQ_Events UNIQUE (ImportId, ImportTypeId) != UNIQUE(ImportId)