Advertisement
MatthijsFontys

Database creation

Mar 11th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.59 KB | None | 0 0
  1. CREATE TABLE Release (
  2.     id INT PRIMARY KEY IDENTITY,
  3.     categoryName VARCHAR(100) NOT NULL,
  4.     ownerId INT NOT NULL,
  5.     releaseName VARCHAR(200) NOT NULL,
  6.     releaseDescription VARCHAR(2000),
  7.     imgLocation VARCHAR(200) NOT NULL,
  8.     releaseDate DateTime NOT NULL,
  9.     creationDate DateTime NOT NULL DEFAULT GETDATE(),
  10.     followerCount INT NOT NULL DEFAULT 0
  11. );
  12.  
  13. CREATE TABLE Category (
  14.     categoryName VARCHAR(100) PRIMARY KEY,
  15.     imgLocation VARCHAR(200) NOT NULL
  16. );
  17.  
  18. CREATE TABLE Comment(
  19.     id INT PRIMARY KEY IDENTITY,
  20.     releaseId INT NOT NULL,
  21.     userId INT NOT NULL,
  22.     postDate DateTime NOT NULL DEFAULT GETDATE(),
  23.     replyId INT,
  24.     commentText VARCHAR(1000) NOT NULL
  25. );
  26.  
  27. CREATE TABLE releaseUser(
  28.     id INT PRIMARY KEY IDENTITY,
  29.     username VARCHAR(20) NOT NULL,
  30.     passHash VARCHAR(200) NOT NULL,
  31.     imgLocation VARCHAR(200),
  32.     accountCreationDate DateTime NOT NULL DEFAULT GETDATE()
  33. );
  34.  
  35. CREATE TABLE User_Release(
  36.     userId INT NOT NULL,
  37.     releaseId INT NOT NULL
  38. );
  39.  
  40.  
  41. ALTER TABLE Release
  42. ADD FOREIGN KEY (categoryName) REFERENCES Category(categoryName);
  43.  
  44. ALTER TABLE Release
  45. ADD FOREIGN KEY (ownerId) REFERENCES releaseUser(id);
  46.  
  47. ALTER TABLE Comment
  48. ADD FOREIGN KEY (releaseId) REFERENCES Release(id);
  49.  
  50. ALTER TABLE Comment
  51. ADD FOREIGN KEY (userId) REFERENCES releaseUser(id);
  52.  
  53. ALTER TABLE User_Release
  54. ADD FOREIGN KEY (userId) REFERENCES releaseUser(id);
  55.  
  56. ALTER TABLE User_Release
  57. ADD FOREIGN KEY (releaseId) REFERENCES Release(id);
  58.  
  59. ALTER TABLE User_Release ADD PRIMARY KEY(userId, releaseId);
  60.  
  61. ALTER TABLE dbo.releaseUser ADD authToken VARCHAR(100);
  62. ALTER TABLE dbo.releaseUser ADD salt VARCHAR(100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement