Advertisement
simonradev

Untitled

Oct 19th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.08 KB | None | 0 0
  1. CREATE TABLE Locations
  2. (
  3.     Id int PRIMARY KEY IDENTITY,
  4.     Latitude float NOT NULL,
  5.     Longitude float NOT NULL
  6. )
  7.  
  8. CREATE TABLE Credentials
  9. (
  10.     Id int PRIMARY KEY IDENTITY,
  11.     Email varchar(30) NOT NULL,
  12.     Password varchar(20) NOT NULL
  13. )
  14.  
  15. CREATE TABLE Users
  16. (
  17.     Id int PRIMARY KEY IDENTITY,
  18.     Nickname varchar(25) NOT NULL,
  19.     Gender char(1) NOT NULL,
  20.     Age int CHECK(Age >= 0) NOT NULL,
  21.     LocationId int FOREIGN KEY REFERENCES Locations(Id) NOT NULL,
  22.     CredentialId int UNIQUE FOREIGN KEY REFERENCES Credentials(Id) NOT NULL
  23. )
  24.  
  25. CREATE TABLE Chats
  26. (
  27.     Id int PRIMARY KEY IDENTITY,
  28.     Title varchar(32) NOT NULL,
  29.     StartDate date NOT NULL,
  30.     IsActive bit NOT NULL
  31. )
  32.  
  33. CREATE TABLE Messages
  34. (
  35.     Id int PRIMARY KEY IDENTITY,
  36.     Content varchar(200) NOT NULL,
  37.     SentOn date NOT NULL,
  38.     ChatId int FOREIGN KEY REFERENCES Chats(Id) NOT NULL,
  39.     UserId int FOREIGN KEY REFERENCES Users(Id) NOT NULL
  40. )
  41.  
  42. CREATE TABLE UsersChats
  43. (
  44.     UserId int FOREIGN KEY REFERENCES Users(Id) NOT NULL,
  45.     ChatId int FOREIGN KEY REFERENCES Chats(Id) NOT NULL,
  46.     CONSTRAINT PK_UsersChats
  47.     PRIMARY KEY (ChatId, UserId)
  48. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement