Lecture 5-6 Flashcards

1
Q

What is the cartesian product?

A

creates a new relation by combining every tuple in 1st with every tuple in the second. Is meaningless unless used by other operators.

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

What is JOIN? What is a natural join?

A

produces a new relation that contains combinations of tuples in 1st and 2nd which satisfy join condition.
A natural join is an equijoin(uses equality) over all common attributes, only one copy of each common attribute is kept.

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

What is division?

A

Produce a relation in which each tuple must appear in the 1st in combination with every tuple in the second.

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

What is the CREATE statement?

A

can be used to create many things, e.g Table, schema, view, etc.

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

What are the main oracle built in data types?

A

Number(p, s): where p is the precision(1-38) and s is the scale(-84, 127) NUMBER(7,2) would be a number with 5 digits before the decimal and two after.
Char(size): fixed length character data
VARCHAR2(size): variable-length character string
DATE
CLOB: A large object containing characters
BLOB: a binary large object
BFILE: Contains a locator to a large binary file.

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

What is the CREATE TABLE command?

A

CREATE TABLE tablename ( column1 datatype (constraint stuff),…
Final constraints
);
Creates a table.

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

What are the main attributes constraints?

A

NOT NULL, DEFAULT , CHECK (checks value of attribute).

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

What are the main integrity constraints?

A

PRIMARY KEY, either at the end of single or attribute or at the end in the form PRIMARY KEY(A1, A2).
Unique clause specifies candidate keys.

for single attribute
FOREIGN KEY REFERENCES table1(A1),
For multiple attributes or in general:
FOREIGN KEY (A1) REFERENCES table1(A2)
Actions can be specified if integrity is broken e.g SET NULL, CASCADE, SET DEFAULT.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we name constraints?

A

Constraints must have unique names and can be named after calling the CONSTRAINT keyword.

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

What is DATE?

A

Oracle uses DATE for both the date and time:
DD for day, MM for numeric month, MON (abbreviated month name), MONTH full month name, YY, YYYY, HH (12 hour format), HH24 24 hour, MI minutes of hour, SS seconds of minute.
SQL has DATE: YYYY-MM-DD, TIME: HH:MM:SS,
TIMESTAMP: YYYY-MM-DD HH:MI:SS[.ssssss]

TO_DATE can be used to specify the format for oracle in the form (date, format).
TO_CHAR can be used to format the output of a date:
TO_CHAR(dateattribute, format).

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

What is the DROP TABLE command?

A

Drops a table, DROP TABLE table [CASCADE CONSTRAINTS];

The CASCADE CONSTRAINTS drops all referential integrity constraints referring to the dropped table.

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

What is the ALTER TABLE command?

A

Can be used to ADD:
ALTER TABLE table ADD attribute VARCHAR(12);
Change:
ALTER TABLE table MODIFY attribute ;
ADD a constraint:
ALTER TABLE table ADD CONSTRAINT cnst etc,
ENABLE CONSTRAINT etc.

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

What is the INSERT command?

A

Inserts a tuple, can be used as
INSERT INTO table VALUES (value1, value2);
in order.
or
INSERT INTO table (A1, A2) VALUES (value1, value2);
If used in the second form all NOT NULL attributes without default values must be mentioned.

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

What do the DELETE and UPDATE commands do?

A

DELETE: Deletes a tuple from table based on criteria
DELETE FROM table WHERE A1 = ‘example’
UPDATE command modifies attribute values:
UPDATE table SET A1 = ‘example’ WHERE A2 = 42

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

What does the SELECT command do?

A

SELECT FROM table WHERE condition;

Selects attributes from tuples which satisfy selection criteria.

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

What does the WHERE clause do?

A

Details the selection criteria, can be very complex and use special operators like IN, BETWEEN, LIKE, IS NULL, or less complicted like =, >, >=, .

17
Q

How does the LIKE operator work?

A

LIKE .
Underscore matches any single character.
% matches a sequence of any number of characters.
These can be used literally using the \ escape character.

18
Q

What does the DISTINCT option do?

A

Removes duplicates from set of tuples.

19
Q

What does GROUP BY do? What does HAVING do?

A

defines a subset of the values of a particular field and to apply an aggregate function to the subsets. e.g SELECT A1, MAX(A2) FROM table GROUP BY A1;
HAVING may follow the GROUP BY and can restrict the groups.
e.g
SELECT A1, MAX(A2) FROM table GROUP BY A1 HAVING MAX(A2) > 21;

20
Q

What does ORDER BY do?

A

Orders output according to values in one or more selected columns. Can be ascending ASC, or DESC descending. Defaults to ascending.
E.g
SELECT * FROM table ORDER BY A1, A2, DESC;

21
Q

What does the UNION operator do?

A

Combines queries and results. There are no column headings in output, duplicate are elminated except in UNION ALL, the queries must have the same number of columns and be data type compatible. Can be Followed by ORDER BY.