Created
March 25, 2020 06:48
-
-
Save eegeeZA/b71e83e9c4f47e38260583c69607be80 to your computer and use it in GitHub Desktop.
MS SQL template for creating new tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- GUID as ID | |
CREATE TABLE [dbo].[TableName1] | |
( | |
[PrimaryKeyName] UNIQUEIDENTIFIER NOT NULL | |
CONSTRAINT [PK_dbo.TableName1] PRIMARY KEY CLUSTERED | |
CONSTRAINT [DF_dbo.TableName1_PrimaryKeyName] DEFAULT NEWSEQUENTIALID(), | |
[ForeignKeyName] UNIQUEIDENTIFIER NOT NULL | |
CONSTRAINT [FK_dbo.TableName1_dbo.TableName2_ForeignKeyName] FOREIGN KEY ([ForeignKeyName]) | |
REFERENCES [dbo].[TableName2] ([TableName2ColumnName]), | |
-- IsActive BIT NOT NULL, | |
); | |
GO | |
-- Integer as ID | |
CREATE TABLE [dbo].[TableName1] | |
( | |
[Id] INT IDENTITY (1, 1) NOT NULL | |
CONSTRAINT [PK_TableName1] PRIMARY KEY CLUSTERED, | |
[ForeignKeyName] UNIQUEIDENTIFIER NOT NULL | |
CONSTRAINT [FK_TableName1_TableName2_ForeignKeyName] FOREIGN KEY ([ForeignKeyName]) | |
REFERENCES [dbo].[TableName2] ([TableName2ColumnName]), | |
-- IsActive BIT NOT NULL, | |
); | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment