SQL3 Flashcards

1
Q

A space?

A

SQL treats a space as an identifier, or match word.

syntax: [ ] or “ “

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

Combining conditions

A

And / Or

syntax:
SELECT name
FROM tablename
WHERE department = ‘shipping’ AND gender =’F’;

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

BETWEEN Clause

A

BETWEEN x AND y

syntax:
SELECT FirstName, LastName
FROM tableName
WHERE hire_date BETWEEN ‘1-Jan-2000’ AND ‘1-JAN-2005’;

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

NOT Clause

A

you can use NOT or < >

syntax:
SELECT FirstName, LastName
FROM tableName
WHERE NOT department = “shipping’;

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

UNION Clause

A

Combine the results of two or more queries into a resulting single set that includes all the rows belonging to the query in that union.

  1. the number and order of the columns must be the same
  2. compatible data type
syntax:
SELECT first, last
FROM employees
WHERE department ='shipping'
UNION
SELECT first, last
FROM employees
WHERE hire_date BETWEEN '1-Jan-2000' AND '1-Jan-2005';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

EXCEPT and INTERSECT Clauses

A

To return distinct values by comparing the result of two queries.

  1. the number and order of the columns must be the same
  2. compatible data type

EXCEPT : returns all that is present in the first SELECT but not in the second.
INTERSECT: returns all rows that are present in BOTH SELECT statements

syntax:
SELECT schoolID
FROM tableName1
EXCEPT
SELECT schoolID
FROM tableName2;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JOIN clauses

A

Combine data columns from multiple tables together (as opposed to UNIONS which combine rows).

JOINS require a ‘common’ column to determine how the data should align (done with an ‘ON’ clause)

Inner joins
Outer joins:
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN
cross joins: return all rows.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

INNER JOIN Clause

A

Return only the data that the two tables have in common. If there is no match on each side, the data is left out.

syntax:
SELECT table1. first, table1.last,
               table2.first, table2.last,
FROM table1 INNER JOIN table2
ON table1. nameID = table2.NameID;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

OUTER JOIN Clause

A

Return ALL data from one side of the join and that which matches on the other (the majority of the time - there is an exception called a FULL OUTER JOIN which is rarely used). OUTER JOINS are directional.

LEFT OUTER JOIN: returns all from the first table and that which matches in the second.
RIGHT OUTER JOIN: returns all from the second table and that which matches in the first
FULL OUTER JOIN: returns all from both sides, but if there is a relationship between the tables (like Customers and Orders) a FULL would return the same results as a directional OUTER JOIN.

syntax:
SELECT table1. first, table1.last,
               table2.first, table2.last,
FROM table1 LEFT OUTER JOIN table2
ON table1. nameID = table2.NameID;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

INSERT Clause

A

syntax:
INSERT INTO tableName (first, last)
VALUES (‘Amy’, ‘Smith’),
(‘Jane’, ‘West’);

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

UPDATE Clause

A

Is to change data in a table or view.

syntax:
UPDATE tableName
SET first =’Ann’
WHERE first =’Amy’;

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

DELETE Clause

A

Remove rows from a table or view.

syntax:
DELETE FROM tableName
WHERE last = ‘Smith’;

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

TRUNCATE Clause

A

Removes the actual data from within the table, but i t leaves the table structure in place for future use.
Delete all the rows using a TRUNCATE TABLE statement

syntax:
TRUNCATE TABLE tableName

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

DROP Clause

A

Removes entire table

syntax:
DROP TABLE tableName

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

Referential Integrity?

also see”Transactional control commands”

A

Does not allow deletion of table unless all of the related tables are deleted using a cascading delete.

  • Ensures a ‘one to many’ relationship between two tables.
  • Use Transactional Control Commands(COMMIT, ROLLBACK, TRAN, SAVEPOINT)

syntax:
BEGIN TRAN
DELETE FROM tableName

example: One Customer can make many Orders AND each order must come from a customer that exists.

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

SELECT Clause

A
Retrieving any data from database
** 3 identify to proper SELECT query: Column, Table, conditions.
syntax:
SELECT first, last
FROM table1;
17
Q

GROUP BY

ORDER BY

A

Group by: to sub total result or perform some other aggregate function on them
Order by: to sort result ( displayed)