Professor Week 4 Flashcards
What are the two main types of data integrity checks?
atomic that looks at the proposed field value – not null, CHECK
relative checks that compare the proposed field value to other value – unique, check (if validation refers other attributes)
How to use Select
SELECT * | attributes to include
FROM tableName
WHERE condition(s);
Don’t have to use WHERE;
Logical Operators
Not – reverses the result
AND – both conditions must eval to true
OR – one or the other
BETWEEN – will include values that are greater or equal to min and less than or equal to the max
Relational Operators
Relational Operators
> Greater Than
>= Greater Than or Equal To
< Less Than
<= Less Than or Equal To
= Equal To
<> Not Equal To
!= Not Equal To
IN (list) Contained in comma-separated list
LIKE string Matches string pattern
LIKE
to specifiy our pattern we use characters and wildcards
characters must be present
wildcards are placeholders
_ means exactly one char
% means 0 or more char
Calculations
Calculations can be performed in the SELECT clause of a SELECT statement
DML: UPDATE
modifies existing user data
UPDATE tableName
SET field1 = value1, fieldN = valueN
WHERE condition;
DML: Delete
Removes record(s) from the table
DELETE
FROM tableName
WHERE condition(s);
ALTER TABLE
to change the structure, instead of dropping it and creating it again
Add/Drop a primary key constraint
Add/Modify/Drop a column
Add/Drop/Modify a default value
cannot modify a table level constraint
ADD | DROP Columns
Alter TABLE tablename
ADD | DROP COLUMN columnName;
Altering defaults
Only “property” that you can alter
ALTER TABLE tableName
ALTER description SET DEFAULT default;
ALTER TABLE tableName
ALTER description DROP DEFAULT;
ALTER TABLE Modify Column
Through the ALTER TABLE … MODIFY COLUMN statement, you can edit an existing
attribute’s specification, including changing the data type or adding/removing a
NOT NULL constraint or DEFAULT value
ALTER TABLE tableName
MODIFY COLUMN attribute DATATYPE [NOT NULL] [DEFAULT];