Created
February 15, 2013 12:33
-
-
Save yetanotherchris/4960139 to your computer and use it in GitHub Desktop.
SQL create tables reference
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
CREATE TABLE sometable | |
( | |
[id] [uniqueidentifier] NOT NULL | |
CONSTRAINT [DF_sometable_id] DEFAULT (newid()), /* This isn't required for DEFAULT */ | |
[userid] [uniqueidentifier] NOT NULL, | |
[accountid] [uniqueidentifier] NOT NULL, | |
[activated] [bit] NOT NULL, | |
[activatedon] [datetime] NULL, | |
[email] [nvarchar](128) NOT NULL, | |
[key] [varchar](32) NOT NULL, | |
PRIMARY KEY NONCLUSTERED (id), /* DONT USE CLUSTERED FOR uniqueidentifier */ | |
CONSTRAINT FK_sometable_userid FOREIGN KEY(userid) REFERENCES users (id), | |
CONSTRAINT FK_sometable_accountid FOREIGN KEY(accountid) REFERENCES accounts (id), | |
) | |
CREATE NONCLUSTERED INDEX [idx_anothertable] ON [dbo].[anothertable] | |
( | |
[sometypeid] ASC, | |
[fileid] ASC, | |
[layoutid] ASC | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment