Skip to content

Instantly share code, notes, and snippets.

@eegeeZA
Created March 25, 2020 06:48
Show Gist options
  • Save eegeeZA/b71e83e9c4f47e38260583c69607be80 to your computer and use it in GitHub Desktop.
Save eegeeZA/b71e83e9c4f47e38260583c69607be80 to your computer and use it in GitHub Desktop.
MS SQL template for creating new tables
-- 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