-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasics.sql
61 lines (46 loc) · 1.59 KB
/
basics.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
create database if not exists Sales;
Use Sales;
create table sales(
purchase_number INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Date_of_purchase DATE NOT NULL,
customer_id INT,
item_code varchar(10) NOT NULL
);
create table customers(
customer_id INT,
First_name varchar(255),
last_name varchar (255),
email_address varchar(255),
number_of_complaints int,
primary key (customer_id)
);
Drop table customers;
CREATE TABLE customers (
customer_id INT AUTO_INCREMENT,
first_name VARCHAR(255),
last_name VARCHAR(255),
email_address VARCHAR(255),
number_of_complaints INT,
PRIMARY KEY (customer_id)
);
CREATE TABLE items (
item_code VARCHAR (255),
item VARCHAR (255),
unit_price NUMERIC (10, 2),
company_id VARCHAR (255)
);
create table companies (
Company_id VARCHAR (255),
company_name VARCHAR (255),
headquarters_phone_number int(12)
);
ALTER Table Sales add Foreign Key (customer_id) References customers (customer_id) on DELETE CASCADE;
Alter table customers add Unique Key (email_address);
Alter table customers drop INDEX email_address;
ALTER TABLE customers
ADD COLUMN gender ENUM('M', 'F') AFTER last_name;
INSERT INTO customers (first_name, last_name, gender, email_address, number_of_complaints)
VALUES ('John', 'Mackinley', 'M', '[email protected]', 0);
Alter table customers change column number_of_complaints number_of_complaints int default 0;
Insert into customers(first_name, last_name, gender) values ('Peter','Figaro','M');
select * from customers;