Skip to content

Instantly share code, notes, and snippets.

@Allon-Guralnek
Created August 27, 2012 12:49
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 Allon-Guralnek/3488126 to your computer and use it in GitHub Desktop.
Save Allon-Guralnek/3488126 to your computer and use it in GitHub Desktop.
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