week 4 Flashcards
How is date formated in SQL
yyyy-mm-dd
Oct 26 2004 ——> 2004-10-26
How is time formated
hh-mm-ss
15:43 ———-> 15-43-21 (15:43:21)
what is the format of Create table
Create Table (department name)(
specify attributes
.
.
.
Specify what the primary key is , unique keys, foreign keys etc
base tables (tables create through a CREATE TABLE statement ) stored on a file by dbms
Virtual tables( created by a CREATE VIEW statement) not stored on a file
How does select work
select [Attribute name}
From [ The table]
where [ Condition]
How does Drop table [table name] RESTRICT work
Table is only dropped if not referenced in constraints (eg dependencies between relations through foreign keys …)
Drop table cascade
ANy dependency is removed along with the table eg( foreign keys)
Drop
ORDER BY
DOESNT CHANGER ORDER OF COLUMNS
eg ORDER BY name ( if nothing here default is ascending)
will order all the instances of name in ascending order
IF there is ORDER BY name asc, studentID desc (asc = ascending , desc = descending)
it will order them by name first and if any tuples have the same name, it will order those that have same name by student id ( in descending order)
<>
comparison operator that means NOT EQUAL TO
Usually seen in where statements in sql
In
eg
select * (all information , all attributes)
From student
where name IN(‘Kate’ , ‘Claire’ , Mike);
selects rows from student where students names are either kate claire or mike
How does alter work when adding something
Try add a constraint
ALTER TABLE EMPLOYEE
ADD FOREIGN KEY (DNO) REFERENCES DEPARTMENT (Dnumber);
How does alter work when dropping something
Try dropping a constraint
ALTER TABLE DEPARTMENT
DROP FOREIGN KEY (MGRSSN);
How does Delete work
DELETE FROM <table name>
WHERE <condition></condition>
DELETE FROM EMPLOYEE
WHERE LNAME=’Brown’
How does update work
UPDATE PROJECT
SET PLOCATION = ‘Bellaire’,
DNUM = 5
WHERE PNUMBER=10;