Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create tables and data for test database 'Wiki' (for http://stackoverflow.com/questions/12138353/)
IF OBJECT_ID('Articles', 'U') IS NOT NULL DROP TABLE Articles
IF OBJECT_ID('Authors', 'U') IS NOT NULL DROP TABLE Authors
CREATE TABLE Authors
(
ID INT NOT NULL IDENTITY,
Name NVARCHAR(100) NOT NULL,
CONSTRAINT PK_Authors PRIMARY KEY CLUSTERED (ID)
)
CREATE TABLE Articles
(
AuthorID INT NOT NULL REFERENCES Authors(ID),
Title NVARCHAR(100) NOT NULL,
Revision INT NOT NULL,
CreatedUTC DATETIME2(2) NOT NULL DEFAULT GETUTCDATE(),
Body NVARCHAR(500),
CONSTRAINT PK_Articles PRIMARY KEY CLUSTERED (AuthorID, Title, Revision)
)
INSERT INTO Authors (Name) VALUES ('John Doe')
INSERT INTO Articles (AuthorID, Title, Revision, Body) VALUES
(1, 'Article A', 1, 'A-1'),
(1, 'Article A', 2, 'A-2'),
(1, 'Article B', 1, 'B-1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.