120 likes | 237 Vues
Quiz for the day 1. given a field definition code char(1) What is the domain of code? Assume that you can enter data from a QWERTY keyboard. Explain in words or enumerate.
E N D
Quiz for the day 1. given a field definition code char(1) What is the domain of code? Assume that you can enter data from a QWERTY keyboard. Explain in words or enumerate. 2. T/F as long as the name of the foreign key is the same as the name of the primary key in the associated table, the data types don’t matter
Another example - Entity-Relationship Diagram (ERD) Student Class Enrol seuID (PK) (FK) dept (PK) (FK) number (PK) (FK) semester (PK) section grade … Some sample records: 111 cosc 3337 SP13 01 cosc 3337 DBMS 111 Jill Student 222 cosc 3337 SP13 01 culf 3331 Amer. D 222 Joe Student 111 culf 3331 SP13 03 How about 111 chem 1301 SP13 02 seuID (PK) fname lname … dept(PK) number (PK) Title …
Integrity Notes from http://www.databasedev.co.uk/database_normalization_process.html • There are 4 types of data integrity: • Entity Integrity ensures that each row (record) is a unique instance in a particular table by enforcing the integrity of the primary key or the identifier column(s) of a table (e.g. ID, Reference Code, etc). • Tool: Primary key Do you know everything there is to know about PK?
Integrity Notes • Domain Integrity ensures validity of entries (data input) for a column through the data type, the data format and the range of possible values (e.g. date, time, age, etc.). • seuID int(6) what is the domain? • gender enum(‘F’, ‘M’); • Application program?
Integrity Notes Referential Integrity preserves the defined relationships between tables when records are added, modified or deleted by ensuring that the key values are consistent across tables; such consistency requires that there are no references to non-existent values and if a key value changes, all references to it change consistently through database, otherwise a key value cannot be changed. constraint foreign key (seuID) references student(seuID) on update cascade on delete cascade
constraint foreign key (seuID) references student(seuID) on update cascade on delete cascade constraint foreign key (seuID) references student(seuID) on update restrict on delete set null Oh man – Parent / Child do I really understand 1 - M
Integrity Notes User-Defined Integrityenables specific (required) business rule(s) to be defined and established in order to provide correct and consistent control of an application's data access (e.g. who can have permissions to modify data, how generated reports should look like, which data can be modified, etc.) Application programs Example: if your web page gathers data and updates the database, can you put audits in your program to make sure that what you ask the database to update/insert meets the business rules set up? The RDBMS can help a lot but it can’t do everything
Surrogate / natural primary keys. CardinalityOptionalitycolumn ordering – what is that about? Data types – see link on website
sql create database, table, user drop insert update delete select alter table show status
sql describe use grant revoke data types
sql primary key constraint foreign key on update on delete unique default not null
sql index