Created
February 23, 2015 08:59
-
-
Save AlexArchive/253e902a3f625d76e7c2 to your computer and use it in GitHub Desktop.
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
USE master; | |
DROP DATABASE Experiment; | |
CREATE DATABASE Experiment; | |
USE Experiment; | |
CREATE TABLE dbo.Tags | |
( | |
TagName NVARCHAR(100) PRIMARY KEY | |
); | |
CREATE TABLE dbo.Posts | |
( | |
PostSlug NVARCHAR(100) PRIMARY KEY, | |
Title NVARCHAR(100) NOT NULL | |
); | |
CREATE TABLE dbo.PostTagJunction | |
( | |
PostSlug NVARCHAR(100), | |
TagName NVARCHAR(100) | |
PRIMARY KEY (PostSlug, TagName), | |
FOREIGN KEY (PostSlug) REFERENCES dbo.Posts (PostSlug) | |
ON DELETE CASCADE, | |
FOREIGN KEY (TagName) REFERENCES dbo.Tags (TagName) | |
); | |
INSERT INTO dbo.Posts | |
VALUES ('hello-world', 'Hello World'); | |
INSERT INTO dbo.Tags | |
VALUES ('Introduction'); | |
INSERT INTO dbo.PostTagJunction | |
VALUES ('hello-world', 'Introduction'); | |
DELETE | |
FROM dbo.Posts | |
WHERE postslug = 'hello-world' | |
SELECT * | |
FROM dbo.Posts | |
SELECT * | |
FROM dbo.PostTagJunction | |
SELECT * | |
FROM dbo.Tags | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment