-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrocery_mysql.sql
59 lines (49 loc) · 1.72 KB
/
grocery_mysql.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
use grocery;
desc inventory_management;
ALTER TABLE inventory_management;
select * from inventory_management;
CREATE TABLE IF NOT EXISTS sales_transactions (
customer_id INT,
item VARCHAR(50),
quantity DECIMAL(10, 2),
price_per_unit DECIMAL(10, 2),
total_price DECIMAL(10, 2),
FOREIGN KEY (item) REFERENCES inventory_management(item)
);
CREATE TABLE if not exists customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(100) NOT NULL,
customer_mobile_number VARCHAR(15) NOT NULL,
subtotal DECIMAL(10, 2) NOT NULL);
select * from customers;
desc customers;
select * from sales_transactions;
create table profit_data(item varchar(100),quantity varchar(100),quantity_purchased int,profit_per_unit int,total_profit int);
-- Alter table to add AUTO_INCREMENT
ALTER TABLE customers
MODIFY customer_id INT AUTO_INCREMENT PRIMARY KEY;
desc customers;
alter table customers drop primary key;
select * from profit_data;
ALTER TABLE customers AUTO_INCREMENT = 1;
truncate sales_transactions;
desc inventory_management;
select * from inventory_management;
ALTER TABLE customers AUTO_INCREMENT = 1;
ALTER TABLE sales_transactions AUTO_INCREMENT = 1;
desc customers;
select * from customers;
select * from sales_transactions;
desc sales_transactions;
select * from profit_data;
alter table sales_transactions modify column customer_id int AUTO_INCREMENT primary key;
desc profit_data;
truncate profit_data;
truncate sales_transactions;
truncate customers;
alter table profit_data add constraint primary key(item);
alter table profit_data add constraint fk foreign key(item) references inventory_management(item);
desc profit_data;
select * from customers;
select * from sales_transactions;
select * from profit_data;