CREATE TABLE employees2 Anne Anders [email protected] 3 Robin Robertson [email protected] 4 Raymond...
Transcript of CREATE TABLE employees2 Anne Anders [email protected] 3 Robin Robertson [email protected] 4 Raymond...
![Page 1: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/1.jpg)
![Page 2: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/2.jpg)
![Page 3: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/3.jpg)
CREATE TABLE employees (
id INT,
first_name VARCHAR(64),
last_name VARCHAR(64),
start DATE
);
![Page 4: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/4.jpg)
CREATE TABLE employees (
id INT UNIQUE,
first_name VARCHAR(64),
last_name VARCHAR(64),
start DATE
);
![Page 5: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/5.jpg)
CREATE TABLE employees (
id INT PRIMARY KEY,
first_name VARCHAR(64),
last_name VARCHAR(64),
start DATE
);
![Page 6: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/6.jpg)
CREATE TABLE employees (
id INT PRIMARY KEY,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
start DATE
);
![Page 7: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/7.jpg)
CREATE TABLE employees (
id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
start DATE
);
![Page 8: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/8.jpg)
CREATE TABLE employees (
email VARCHAR(64)
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
start DATE,
PRIMARY KEY (email)
);
![Page 9: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/9.jpg)
CREATE TABLE employees (
email VARCHAR(64)
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
role VARCHAR(32),
start DATE,
PRIMARY KEY (email),
FOREIGN KEY (role) REFERENCES roles(name)
);
![Page 10: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/10.jpg)
ALTER table_name
ADD CONSTRAINT constraint_name
FOREIGN KEY (columns)
REFERENCES parent_table(columns)
ON DELETE action
ON UPDATE action;
![Page 11: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/11.jpg)
SHOW CREATE TABLE table_name
ALTER table_name
DROP FOREIGN KEY constraint_name
![Page 12: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/12.jpg)
![Page 13: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/13.jpg)
Country Capital
Canada Ottawa
UK London
USA Washington D.C.
Brazil Brasilia
![Page 14: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/14.jpg)
Id name Email
1 Bob Jones [email protected]
2 Steve Smith [email protected]
3 Robin Robertson [email protected]
4 Sam Samuels [email protected]
Instructors
Id code instructor_id
1 math * 1000 1
2 econ * 2500 2
3 bio * 4000 1
4 math * 1000 3
Class
![Page 15: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/15.jpg)
Id name Email
1 Tom Thompson [email protected]
2 Anne Anders [email protected]
3 Robin Robertson [email protected]
4 Raymond Chen [email protected]
Student
Id code instructor_id
1 math * 1000 1
2 econ * 2500 2
3 bio * 4000 1
4 math * 1000 3
Classclass_id student_id
1 1
1 2
3 3
2 4
4 1
Student - Class
junction
![Page 16: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/16.jpg)
(1) select * from table1, table2
(2) select * from table1 join table2
table1 table2
![Page 17: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/17.jpg)
select * from table1, table2
Country Flag
Canada Maple Leaf
UK Union Jack
USA Old Glory
Brazil A Auriverde
Country Capital
Canada Ottawa
UK London
USA Washington D.C.
Brazil Brasilia
Country Capital Country Flag
Canada Ottawa Canada Maple Leaf
Canada Ottawa UK Union Jack
Canada Ottawa USA Old Glory
Canada Ottawa Brazil A Auriverde
UK London Canada Maple Leaf
…
![Page 18: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/18.jpg)
SELECT columns
FROM t1
JOIN t2 ON join_condition1
![Page 19: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/19.jpg)
select * from table1, table2
table1 table2
![Page 20: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/20.jpg)
select * from table1 join table2
on table1.country = table2.country
Country Flag
Canada Maple Leaf
UK Union Jack
USA Old Glory
Brazil A Auriverde
Country Capital
Canada Ottawa
UK London
USA Washington D.C.
Brazil Brasilia
Country Capital Country Flag
Canada Ottawa Canada Maple Leaf
UK Lodon UK Union Jack
USA Washington D.C. USA Old Glory
Brazil Brasilia Brazil A Auriverde
![Page 21: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/21.jpg)
SELECT columns
FROM t1
LEFT JOIN t2 ON join_condition1
WHERE conditions;
![Page 22: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/22.jpg)
select * from table1 left join table2
table1 table2
![Page 23: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/23.jpg)
SELECT columns
FROM t1
RIGHT JOIN t2 ON join_condition1
WHERE conditions;
![Page 24: CREATE TABLE employees2 Anne Anders anne@gmail.com 3 Robin Robertson robin@hotmail.com 4 Raymond Chen rchen@gmail.com Student Id code instructor_id 1 math * 1000 1 2 econ * 2500 2](https://reader036.fdocuments.in/reader036/viewer/2022062606/5fde6ecc59372b58b24af530/html5/thumbnails/24.jpg)
select * from table1 right join table2
table1 table2