SHARE
TWEET

Untitled

a guest Feb 17th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. begin tran
  2. CREATE TABLE Locations
  3. (
  4.     Id INT PRIMARY KEY,
  5.     Latitude FLOAT,
  6.     Longitude FLOAT
  7. )
  8.  
  9. CREATE TABLE [Credentials]
  10. (
  11.     Id INT PRIMARY KEY,
  12.     Email VARCHAR(30),
  13.     Password VARCHAR(30)
  14. )
  15.  
  16. CREATE TABLE Chats
  17. (
  18.     Id INT PRIMARY KEY,
  19.     Title VARCHAR(32),
  20.     StartDate DATE,
  21.     IsActive BIT
  22. )
  23.  
  24. CREATE TABLE Users
  25. (
  26.     Id INT PRIMARY KEY,
  27.     Nickname VARCHAR(25),
  28.     Gender CHAR(1),
  29.     Age INT,
  30.     LocationID INT FOREIGN KEY REFERENCES Locations(Id),
  31.     CredentialID INT FOREIGN KEY REFERENCES [Credentials](ID) UNIQUE
  32. )
  33.  
  34. CREATE TABLE [Messages]
  35. (
  36.     Id INT PRIMARY KEY,
  37.     Content VARCHAR(200),
  38.     SentOn DATE,
  39.     ChatId INT FOREIGN KEY REFERENCES Chats(Id),
  40.     UserId INT FOREIGN KEY REFERENCES Users(Id)
  41. )
  42.  
  43. CREATE TABLE UsersChats
  44. (
  45.     ChatId INT REFERENCES Chats(Id),
  46.     UserId INT REFERENCES Chats(Id),
  47.     PRIMARY KEY (ChatId, UserId)
  48. )
  49. rollback;
RAW Paste Data
Top