Professional Documents
Culture Documents
► Keys are part of a relational database and a vital part of the structure of a table. They ensure each record within a table can be
uniquely identified by one or a combination of fields within the table. They help enforce integrity and help identify the relationship
between tables.
► Types of key:
► Super Key
► Candidate Key
► Primary Key
► Foreign Key
► Simple Key
Keys definition
► Super Key: any combination of fields within a table that uniquely identifies each record within that table (sets of
columns that it`s true to be key).
► Candidate Key: subset of a super key.
► Primary Key: a candidate key that is most appropriate to be the main reference key for the table (chosen key).
► Secondary Key or Alternative Key: keys left after chose the PK from candidate key.
► Foreign Key: a primary key from one table that appears as a field in another where the first table has a relationship to the second.
► Simple Key: Any of the keys described before consists of a single field to uniquely identify a record. In addition, the field in itself
cannot be broken down into other fields (ie.id, email).
Primary key VS foreign key
Only one primary key in a table More than one foreign key in a table
PK uniquely identify a record in the table Foreign key is a field in the table that is
PK in another table
Key categories
► Natural key : A key that is formed of attributes that already exist in the real world.
► Example, the Social Security Number (SSN) , email , mobile number.
► The whole purpose of constraints is to maintain the data integrity during an update/delete/insert into a table.
► Types of constraints
► UNINOT NULL: makes sure that a column does not hold NULL value.
► UNIQUE: enforces a column to have unique values (cannot have duplicate values).
► DEFAULT: provides a default value to a column when there is no value provided while inserting a record into a table.
► CHECK: used for specifying range of values for a particular column of a table.
► Key Constraints (PK , FK):
► Primary key: Each table has certain set of columns, and each column allows a same type of data, based on its data type.
The column does not accept values of any other data type.
► Foreign keys: the columns of a table that points to the PK of another table. They act as a cross-reference between
tables.
► Domain constraints: The column does not accept values of any other data type. Domain Constraint = data type + Constraints
(NOT NULL / UNIQUE / PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT).
► Mapping constraints: mapping cardinality (relation).
The Database Terms of Reference
10
Instance and schema in DBMS
► Definition of schema: Design of a database is called the schema. Schema is of three types: (Physical schema, view
schema and conceptual schema).
► Basically, schema contains the structure and mapping of the object in it. It will remain same most of the time,
unless we modify the structure of the objects in schema.
► Definition of instance: The data stored in database at a particular moment of time is called instance of
database. Database schema defines the variable declarations in tables that belong to a particular database; the value of
these variables at a moment of time is called the instance of that database.
► i.e.; at any particular point in time, what is the state of database with data values in its object is called database
instance. It changes from time to time.