Exam 1.2 Flashcards
(24 cards)
Order for SQL commands
Select
From
Where
Group By
Having
Order By
Types of datat in SQL
Varchar(size), Number, Integer, Char
How do integrity constraints work
-must apply to all instances of database
-defined when schema is modified
-checked when relations are modified
what is a superkey
A key that contains primary key and isn’t minimal
Ways of defining primary key x
X Primary Key [after it]
Primary key(x) [on seperate line]
What seperates data in tables and what ends them
commas and semicolons
what is entire table stored in
parenthesis
What happens if primary key isn’t defined
Database will define one on its own
Not null constraint
makes it so something cannot be null candidate keys and primary keys have this feature
How would a candidate key X be defined
using UNIQUE(X) keyword
how do foreign keys work
they are used to reference another item in a parent table
How would you make a foreign key x
FOREIGN KEY (x) references [other table] (parent id)
T or F can foreign keys be a tuple
True they can be a set they just must be unique
T or F foreign keys must have the same name as their parents
No foreigns keys can have any name
What are 3 ways to deal with deletes and preserving referential integrity
disallowing delete
cascade delete
set to default or null
What are the keywords for referential integrity
No action- does nothing
restrict - disallows deletion
cascade delete- deletes all things pointing to deleted
set null /set default
How does drop table command work
drops table according to how the drop is specified could be drop tabl cascade
What does drop table cascade constaints do
deletes entire table and foreign keys constaint is deleting reverting column back to what is was before
How does alter tables work
Start with Alter table [tname]
and then what you want to do
What are the different things that can be done with alter table
drop column
add column datatype
add key constraints ex ADD CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES parent_table(parent_column);
How to insert into table
INSERT INTO table_name (column_name) VALUES (1234567890.99);
How to use delete keyword
Same as a select but delete at the top instead
How does update keyword work
has update, set, where
how does Select statement work
has select from and where