-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchema2.sql
More file actions
150 lines (108 loc) · 2.62 KB
/
Schema2.sql
File metadata and controls
150 lines (108 loc) · 2.62 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
create table test (
my_date date,
my_time time,
my_datetime datetime
);
insert into test
values (current_date(), current_time(), now()
);
insert into test
values (current_date() + 1, null, null
);
select * from test;
drop table test;
create table product (
product_id int,
product_name VARCHAR(25) UNIQUE,
price decimal(4, 2)
);
alter table product
add constraint
UNIQUE (product_name);
insert into product
VALUES
(101, "Pommes", 3.50),
(102, "Burger", 9.99),
(103, "Drink", 2.99);
create table product (
product_id int,
product_name VARCHAR(25),
price decimal(4, 2) NOT NULL
);
alter table product
modify price DECIMAL (4, 2) NOT NULL;
select * from customers;
insert into product
values (104, "cookie", 0);
select * from product;
drop table transactions;
create table employees (
employee_id int,
first_name VARCHAR (50),
last_name VARCHAR (50),
hourly_pay decimal (4, 2),
hire_date date,
constraint chk_hourly_pay check (hourly_pay >= 10.00)
);
alter table employees
add constraint chk_hourly_pay check (hourly_pay >= 10.00);
insert into employees
values (6, "deadpool", "wolverine", 10.29, "2023-04-20");
alter table employees
drop check chk_hourly_pay;
select * from employees;
select * from product;
insert into product
values (105,"straw", 0.00),
(106, "napkins", 0.00),
(107, "spoon", 0.00);
delete from product
where product_id >= 104;
delete from transactions;
create table product (
product_id int,
product_name VARCHAR(25),
price decimal(4, 2) DEFAULT 0
);
alter table product
alter price set default 0;
insert into product (product_id, product_name)
values (104, "straw"),
(105, "spoon"),
(106, "napkins");
select * from product;
create table transactions(
transaction_id int,
amount decimal (5, 2),
transaction_date datetime DEFAULT NOW()
);
insert into transactions (transaction_id, amount)
values (3, 9.99);
drop table transactions;
select * from transactions;
create table transactions (
transaction_id int PRIMARY KEY,
amount DECIMAL (5, 2)
);
alter table transactions
add constraint
PRIMARY KEY(transaction_id);
insert into transactions
values (null, 9.99);
select amount
from transactions
where transaction_id = 0003;
drop table transactions;
create table transactions (
transaction_id int PRIMARY KEY AUTO_INCREMENT,
amount decimal (5, 2)
);
insert into transactions (amount)
values (2.99);
delete from transactions
where transaction_id = 4;
alter table transactions
auto_increment = 1000;
insert into transactions (amount)
values (5.99);
select * from transactions;