-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_CRUD.sql
65 lines (40 loc) · 1.11 KB
/
2_CRUD.sql
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
CREATE database cats;
USE cats;
create table cats
(
cat_id INT NOT NULL auto_increment,
name VARCHAR(100),
breed VARCHAR(100),
age INT,
PRIMARY KEY (cat_id)
);
DESC cats;
INSERT INTO cats(name,breed,age)
VALUES ('Ringo','Tabby',4),
('Cindy','Maine Coon',10),
('Dumbledore','Maine Coon',11),
('Egg','Persian',4),
('Misty','Tabby',13),
('George Michael','Ragdoli',9),
('Jackson','Sphynx',7);
SELECT name FROM cats;
SELECT age FROM cats;
SELECT name,age FROM cats;
SELECT breed,name,age FROM cats;
SELECT * FROM cats WHERE age=4;
SELECT * FROM cats WHERE name='egg';
SELECT cat_id FROM cats;
SELECT name, breed FROM cats;
SELECT * FROM cats WHERE breed='tabby';
SELECT * FROM cats WHERE cat_id=age;
SELECT name AS cat_name FROM cats WHERE cat_id=age;
UPDATE cats SET breed='Shorthair' WHERE breed='Tabby';
UPDATE cats SET age=14
WHERE name='Misty'
UPDATE cats SET name="Jack" WHERE name='Jackson';
UPDATE cats SET breed='British Shorthair' WHERE name="Ringo";
UPDATE cats SET age=12 WHERE breed='Maine Coon';
DELETE FROM cats WHERE age=4;
DELETE FROM cats WHERE age=cat_id;
SELECT * FROM cats;
DELETE FROM cats;