Skip to content

Instantly share code, notes, and snippets.

@brianvp
Created October 7, 2015 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianvp/8bfb8aa3d9ec054e5531 to your computer and use it in GitHub Desktop.
Save brianvp/8bfb8aa3d9ec054e5531 to your computer and use it in GitHub Desktop.
SQL Server Tip #1: Basic Table Template
CREATE TABLE tempdb.dbo.temp1
(
Temp1Id INT IDENTITY(1,1) NOT NULL
CONSTRAINT temp1PrimaryKey PRIMARY KEY CLUSTERED,
VALUE VARCHAR(25),
DateModified datetime2,
DateCreated datetime2 default getdate()
)
GO
CREATE TABLE tempdb.dbo.temp2
(
Temp2Id INT IDENTITY(1,1) NOT NULL
CONSTRAINT temp2PrimaryKey PRIMARY KEY CLUSTERED,
Temp1Id INT NOT NULL
CONSTRAINT Temp2Temp1ForeignKey FOREIGN KEY (Temp1Id)
REFERENCES dbo.temp1(Temp1Id),
VALUE VARCHAR(25) NULL,
DateModified datetime2,
DateCreated datetime2 default getdate()
)
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment