MySQL Theory
MySQL Theory
Levels of Abstraction
• Views describe how users see the data
• Conceptual Schema defines logical structure
• Physical Schema describes the files and indexes
used.
• Schemes are defined using DDL (Data Definition
Language)
• Data is modified/queried by DML (Data
Manipulation Language)
• There are three levels of abstraction:-
◦ Physical Level:- Describes storage of record
◦ Logical Level:- Describes relationships and
data in a database.
◦ View Level: Application programs hide details
and information.
Database Terminologies
• Relation: A table in a database
• Tuple/Record: A row in a table
• Field/Attributes: A column in a table
• Domain: Possible pool of values for a specific
column
• Degree: Number of columns in a table at that
instance
• Cardinality: Number of rows in a table at that
instance.
Keys
Key is used to uniquely identify any record in a table
or establish relationships between tables.
• Primary Key
◦ It uniquely identifies each record in a table.
◦ It should contain unique values and not null
values
◦ Each table can have only one primary key.
• Candidate Key
◦ It is a super key with no repeated attributes.
◦ Primary key should be selected from the
candidate keys.
◦ A table can have multiple candidate keys.
• Alternate Key
◦ They are candidate keys which are not primary
keys.
◦ Database administrator chooses a different
key as the primary key.
Constraints
UNIQUE:- Ensures all values in a column are
different. It allows one null value
NOT NULL:- Ensures that all values in a column are
not null. Thus, it makes this column to be mandatory.
DEFAULT:- It is the value added to each row in a
column if no other value is specified.
CHECK:- Ensures that all values in a column satisfy
certain condition(s).