Midterms - syntax. joins, checks Flashcards

(38 cards)

1
Q

Syntax

Adding Pk constraint to an existing table using ALTER

A
ALTER TABLE Employee
ADD CONSTRAINT empPk PRIMARY KEY (empId);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Syntax

Composite Primary Key

A
ALTER TABLE Employee
ADD CONSTRAINT empSkillPk
PRIMARY KEY (empId, SkillId);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Syntax

Adding Fk constraint to existing table using ALTER

A
ALTER TABLE Employee
ADD CONSTRAINT empFk FOREIGN KEY (deptId) REFERENCES Department (deptId);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Syntax

Insert

A
INSERT INTO Employee (empId, salaryCode, lastName)
VALUES (62, 11, 'Halrpert');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Syntax

Update

A
UPDATE Employee
SET phone = '0928 - 960 - 1234'
WHERE empId = 29;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax

Delete

A
DELETE FROM Employee
WHERE empId = 29;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Syntax

Select

A
SELECT empName
FROM Employee
WHERE empId = 33;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Identification

A query pulls information from one or more relations and temporarily creates a new relation

A

Result set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

Correlated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

Non-correlated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Identification

Another way of combining data from multiple tables

A

Joins

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Syntax

Inner Join

A
SELECT empName, deptName
FROM Employee e INNER JOIN Department d ON e.deptId = d.deptId;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Syntax

Left Outer Join

A
SELECT empName, deptName
FROM Employee e LEFT OUTER JOIN Department d ON e.deptId = d.deptId;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Syntax

Right Outer Join

A
SELECT empName, deptName
FROM Employee e RIGHT OUTER JOIN Department d ON e.deptId = d.deptId;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Syntax

Full Outer Join

A
SELECT empName, deptName
FROM Employee e
FULL OUTER JOIN Department d ON e.deptId = d.deptId;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Syntax

Union

A
SELECT e.empName, d.deptName FROM employee e LEFT OUTER JOIN department d ON e.deptId = d.deptId 
UNION 
SELECT e.empName, d.deptName FROM employee e RIGHT OUTER JOIN department d ON e.deptId = d.deptId;
17
Q

Syntax

Union All

A
SELECT e.empName, d.deptName 
FROM employee e LEFT OUTER JOIN department d ON e.deptId = d.deptId 
UNION ALL
SELECT e.empName, d.deptName 
FROM employee e RIGHT OUTER JOIN department d ON e.deptId = d.deptId;
18
Q

Syntax

Alter and Drop

A
ALTER TABLE Employee DROP CONSTRAINT empFk;
19
Q

Syntax

Deleting a Database

A

DROP TABLE Employee;

20
Q

Syntax

Check Constraint

A

ALTER TABLE Employee
ADD CONSTRAINT length
CHECK (LENGHT(deptId) >=3);

21
Q

Identification

Retrieves records that have matching values in both tables based on a specified condition, only the rows with matches in both tables are included in the result set

22
Q

Identification

Returns all records from the left table and any matching records from the right table. If there’s no match, NULL values are returned for the right table’s columns.

A

Left Outer Join

23
Q

Identification

Returns all records from the right table along with any matching records from the left table. If there’s no match, NULL values are returned for the left table’s columns.

A

Right Outer Join

24
Q

Identification

combines the results of two or more SELECT queries into a single result set, removing duplicate rows

25
# Identification combines the results of two or more SELECT queries into a single result set, including all duplicate rows
Union All
26
# Identification Returns all records from both tables, combining rows with matching pairs. If no match exists, the missing values in both tables are filled with NULL
Full Outer Join
27
# Identification is used to ensure that values in a column meet a specific condition before they are accepted into the database
Check Constraint
28
# Define Result set
A query pulls information from one or more relations and temporarily creates a new relation
29
# Define Correlated
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.
30
# Define Non-correlated
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
31
# Define Joins
Another way of combining data from multiple tables
32
# Define Inner Join
Retrieves records that have matching values in both tables based on a specified condition, only the rows with matches in both tables are included in the result set
33
# Define Left Outer Join
Returns all records from the left table and any matching records from the right table. If there's no match, NULL values are returned for the right table's columns.
34
# Define Right Outer Join
Returns all records from the right table along with any matching records from the left table. If there's no match, NULL values are returned for the left table's columns.
35
# Define Union
combines the results of two or more SELECT queries into a single result set, removing duplicate rows
36
# Define Union All
combines the results of two or more SELECT queries into a single result set, including all duplicate rows
37
# Define Full Outer Join
Returns all records from both tables, combining rows with matching pairs. If no match exists, the missing values in both tables are filled with NULL
38
# Define Check Constraint
is used to ensure that values in a column meet a specific condition before they are accepted into the database