Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
IF (NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'UserAccount'))
BEGIN
CREATE TABLE [dbo].[UserAccount] (
[UserAccountId] INT IDENTITY (1, 1) NOT NULL,
[DisplayName] NVARCHAR (20) NULL,
[Email] NVARCHAR (129) NOT NULL,
[CreateDate] DATETIME NOT NULL
);
ALTER TABLE [dbo].[UserAccount]
ADD CONSTRAINT [PK_UserAccount] PRIMARY KEY CLUSTERED ([UserAccountId] ASC) WITH (FILLFACTOR = 80, ALLOW_PAGE_LOCKS = OFF, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);
CREATE TABLE [dbo].[Channel] (
[ChannelId] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (128) NOT NULL,
[UserAccountId] INT NOT NULL,
[ModifyDate] DATETIME NOT NULL
);
ALTER TABLE [dbo].[Channel]
ADD CONSTRAINT [PK_Channel] PRIMARY KEY CLUSTERED ([ChannelId] ASC) WITH (FILLFACTOR = 80, ALLOW_PAGE_LOCKS = OFF, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);
ALTER TABLE [dbo].[Channel]
ADD CONSTRAINT [FK_Channel_UserAccountId_UserAccount_UserAccountId] FOREIGN KEY ([UserAccountId]) REFERENCES [dbo].[UserAccount] ([UserAccountId]) ON DELETE NO ACTION ON UPDATE NO ACTION;
CREATE TABLE [dbo].[Media] (
[MediaId] INT IDENTITY (1, 1) NOT NULL,
[ChannelId] INT NOT NULL,
[Title] NVARCHAR (128) NULL,
[Width] INT NOT NULL,
[Height] INT NOT NULL,
[Duration] INT NOT NULL,
[ContentUrl] NVARCHAR (MAX) NULL,
);
ALTER TABLE [dbo].[Media]
ADD CONSTRAINT [PK_Media] PRIMARY KEY CLUSTERED ([MediaId] ASC) WITH (FILLFACTOR = 80, ALLOW_PAGE_LOCKS = OFF, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF);
ALTER TABLE [dbo].[Media]
ADD CONSTRAINT [FK_Media_ChannelId_Channel_ChannelId] FOREIGN KEY ([ChannelId]) REFERENCES [dbo].[Channel] ([ChannelId]) ON DELETE NO ACTION ON UPDATE NO ACTION;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment