Lecture 5-6 Flashcards
What is the cartesian product?
creates a new relation by combining every tuple in 1st with every tuple in the second. Is meaningless unless used by other operators.
What is JOIN? What is a natural join?
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.
What is division?
Produce a relation in which each tuple must appear in the 1st in combination with every tuple in the second.
What is the CREATE statement?
can be used to create many things, e.g Table, schema, view, etc.
What are the main oracle built in data types?
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.
What is the CREATE TABLE command?
CREATE TABLE tablename ( column1 datatype (constraint stuff),…
Final constraints
);
Creates a table.
What are the main attributes constraints?
NOT NULL, DEFAULT , CHECK (checks value of attribute).
What are the main integrity constraints?
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 can we name constraints?
Constraints must have unique names and can be named after calling the CONSTRAINT keyword.
What is DATE?
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).
What is the DROP TABLE command?
Drops a table, DROP TABLE table [CASCADE CONSTRAINTS];
The CASCADE CONSTRAINTS drops all referential integrity constraints referring to the dropped table.
What is the ALTER TABLE command?
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.
What is the INSERT command?
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.
What do the DELETE and UPDATE commands do?
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
What does the SELECT command do?
SELECT FROM table WHERE condition;
Selects attributes from tuples which satisfy selection criteria.