Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07f4f07

Browse filesBrowse files
committed
newDB
PostsDB
1 parent 571ef01 commit 07f4f07
Copy full SHA for 07f4f07

File tree

Expand file treeCollapse file tree

3 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+35
-0
lines changed

‎PostsDB/PostsDB--DDL.sql

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE DATABASE IF NOT EXISTS postsdb;
2+
USE postsdb;
3+
4+
CREATE TABLE IF NOT EXISTS user (
5+
id int auto_increment primary key PRIMARY KEY,
6+
username varchar(100) not null unique,
7+
password varchar(100) not null
8+
);
9+
10+
/*One user cannot post 2 posts with the same title*/
11+
12+
CREATE TABLE IF NOT EXISTS post (
13+
id int auto_increment primary key,
14+
title varchar(100) not null,
15+
content text not null,
16+
fk_user_id int not null,
17+
foreign key (fk_user_id) references user(id),
18+
constraint unique_post unique (title, fk_user_id)
19+
);

‎PostsDB/PostsDB--DML.sql

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use postsdb;
2+
3+
insert into user (id, username, password) values
4+
(1, '@bishop', '1234'),
5+
(2, '@data', '1234'),
6+
(3, '@bishop&co.', '1234');
7+
8+
insert into post (title, content, fk_user_id) values
9+
('How...', 'Forget it... NEVERMIND!', 1),
10+
('How to...', 'Forget it... NEVERMIND!', 1),
11+
('How to...', 'Forget it... NEVERMIND!', 2),
12+
('How to do...', 'Forget it... NEVERMIND!', 2),
13+
('How to do...', 'Forget it... NEVERMIND!', 3),
14+
('How to do your', 'Forget it... NEVERMIND!', 3);

‎PostsDB/PostsDB--DQL.sql

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
use postsdb;
2+
select * from post;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.