-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.sql
More file actions
45 lines (36 loc) · 1.14 KB
/
blog.sql
File metadata and controls
45 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
CREATE DATABASE blog_database;
USE blog_database;
CREATE TABLE authors(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100)NOT NULL
);
CREATE TABLE posts(
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
word_count INT NOT NULL,
views INT NOT NULL,
author_id INT,
FOREIGN KEY (author_id) REFERENCES authors(id)
);
INSERT INTO authors(name)
VALUES
('Maria Charlotte'),
('Juan Perez'),
('Gemma Alcocer');
SELECT * FROM authors;
ALTER TABLE authors AUTO_INCREMENT = 1;
DELETE FROM authors;
INSERT INTO posts(title,word_count,views,author_id)
VALUES
('Best Paint Colors',814,14,1),
('Small Space Decorating Tips',1146,221,2),
('Hot Accessories',986,105,1),
('Mixing Textures',765,22,1),
('Kitchen Refresh',1242,307,2),
('Homemade Art Hacks',1002,193,1),
('Refinishing Wood Floors',1571,7542,3);
SELECT * FROM posts;
SELECT authors.name, posts.title
FROM posts
JOIN authors
ON posts.author_id = authors.id;