Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE users (
- id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- username NVARCHAR(30) NOT NULL UNIQUE,
- password NVARCHAR(50) NOT NULL
- )
- CREATE TABLE sections (
- id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- name NVARCHAR(50) NOT NULL UNIQUE,
- )
- CREATE TABLE posts (
- id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- description NVARCHAR(255) NOT NULL,
- image_url NVARCHAR(255) NOT NULL,
- date_time DATETIME DEFAULT CURRENT_TIMESTAMP,
- author_id BIGINT NOT NULL,
- section_id BIGINT NOT NULL,
- CONSTRAINT FK_userId_users_posts FOREIGN KEY(author_id) REFERENCES users(id),
- CONSTRAINT FK_sectionId_sections FOREIGN KEY(section_id) REFERENCES sections(id)
- )
- CREATE TABLE tags (
- id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- name VARCHAR(50) NOT NULL
- )
- CREATE TABLE comments (
- id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
- description NVARCHAR(1000) NOT NULL,
- date_time DATETIME DEFAULT CURRENT_TIMESTAMP,
- author_id BIGINT NOT NULL,
- post_id BIGINT NOT NULL,
- CONSTRAINT FK_userId_users_comments FOREIGN KEY(author_id) REFERENCES users(id),
- CONSTRAINT FK_postId_posts_comments FOREIGN KEY(post_id) REFERENCES posts(id)
- )
- CREATE TABLE post_tag (
- post_id BIGINT NOT NULL,
- tag_id BIGINT NOT NULL,
- CONSTRAINT PK_postId_examId PRIMARY KEY(post_id, tag_id),
- CONSTRAINT FK_postId_posts FOREIGN KEY(post_id) REFERENCES posts(id),
- CONSTRAINT FK_tagId_tags FOREIGN KEY (tag_id) REFERENCES tags(id)
- )
- CREATE TABLE rating_posts_users (
- post_id BIGINT NOT NULL,
- user_id BIGINT NOT NULL,
- grade INT NOT NULL,
- CONSTRAINT PK_raiting_posts_users PRIMARY KEY(post_id, user_id),
- CONSTRAINT FK_postId_userId_posts FOREIGN KEY (post_id) REFERENCES posts(id),
- CONSTRAINT FK_postId_userId_users FOREIGN KEY (user_id) REFERENCES users(id),
- CONSTRAINT CHK_gradeValue CHECK (grade = -1 OR grade = 1)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement