final Flashcards
SQL DDL
sequel data definition language: define relations, integrity constraints, domains,
types in SQL
char(n) fixed len string
varchar(n) variabe len string
int integer
float(n) n digit float
create table example
create tableinstructor(ID char(5),name varchar(20),salary numeric(8,2))
integrity constraints
ensure certain logical things do not happen, ie not null, primary key, foreign key
integrity constraints example
create tableinstructor(ID char(5),name varchar(20) not null,dept_namevarchar(20),salary numeric(8,2),primary key (ID),foreign key (dept_name) referencesdepartment)
not null
can be a constraint: used in create to ensure not null
can be a test: ie select all * where x is not null
insert example
insert into instructor values (‘10211’, ‘Smith’, ’Bio’, 66000);
delete example
delete from r where conditions
drop table
drop table r
alter example
Alter table – add/remove attributes●Structure:
alter table r add A D
alter table r drop A
basic query
select x
from y
where z
search for a substring
select name
from instructor
where name like ‘%dar%’;
more substring
intro% (intro followed by anything)
%mid%
‘___’ 3 characters
‘___%’ 3 or more chars
list people alphabetically
select distinct name
from instructor
order by name asc/desc
between exmp
… where att between 100 and 200
union
combine 2 relations
select …
union
select …
intersect
combine things in common
see union
except
remove items in common
aggregate functions
select x count(y)
from z
group by x
conditions with aggro func
select ... group by x having count(y) > a
nested subqueries
queries where a select-from-where exists in another query
used for membership, comparisons, cardinality
NS for membership
select from
where att in (select from where)
rename
x as y
some
search thru a NS for any member
select from
where x > some NS
all
some but for all in the set returned by a query
unique
returns tuples from an NS where there are no duplicates
delete
delete tuples from relation
delete
from r
where …
update
change values of atts on a where cond
update instructor
set att = att + 4
where att > x