Midterms - syntax. joins, checks Flashcards
Syntax
Adding Pk constraint to an existing table using ALTER
ALTER TABLE Employee ADD CONSTRAINT empPk PRIMARY KEY (empId);
Syntax
Composite Primary Key
ALTER TABLE Employee ADD CONSTRAINT empSkillPk PRIMARY KEY (empId, SkillId);
Syntax
Adding Fk constraint to existing table using ALTER
ALTER TABLE Employee ADD CONSTRAINT empFk FOREIGN KEY (deptId) REFERENCES Department (deptId);
Syntax
Insert
INSERT INTO Employee (empId, salaryCode, lastName) VALUES (62, 11, 'Halrpert');
Syntax
Update
UPDATE Employee SET phone = '0928 - 960 - 1234' WHERE empId = 29;
Syntax
Delete
DELETE FROM Employee WHERE empId = 29;
Syntax
Select
SELECT empName FROM Employee WHERE empId = 33;
Identification
A query pulls information from one or more relations and temporarily creates a new relation
Result set
Identification
Dependent on the outer query. References columns or relies on a value from the outer query. Is executed repeatedly, once for each row in the outer query.
Correlated
Identification
Independent of the outer query. Does not reference any value or columns from the outer query. Executed once and the result is used by the outer query.
Non-correlated
Identification
Another way of combining data from multiple tables
Joins
Syntax
Inner Join
SELECT empName, deptName FROM Employee e INNER JOIN Department d ON e.deptId = d.deptId;
Syntax
Left Outer Join
SELECT empName, deptName FROM Employee e LEFT OUTER JOIN Department d ON e.deptId = d.deptId;
Syntax
Right Outer Join
SELECT empName, deptName FROM Employee e RIGHT OUTER JOIN Department d ON e.deptId = d.deptId;
Syntax
Full Outer Join
SELECT empName, deptName FROM Employee e FULL OUTER JOIN Department d ON e.deptId = d.deptId;