Records
Records are composed of fields, each of which contains one item of information. A set of records constitutes a file. For example, a personnel file might contain records that have three fields: a name field, an address field, and a phone number field.
A single entry in a table is called a Tuple or Record or Row. A tuple in a table represents a set of related data. For example, the above Employee table has 4 tuples/records/rows.
Following is an example of single record or tuple.
1 | Adam | 34 | 13000 |
Attributes
A table consists of several records(row), each record can be broken down into several smaller parts of data known as Attributes. The above Employee table consist of four attributes, ID, Name, Age and Salary.
Attribute Domain
When an attribute is defined in a relation(table), it is defined to hold only a certain type of values, which is known as Attribute Domain.
Hence, the attribute Name will hold the name of employee for every tuple. If we save employee’s address there, it will be violation of the Relational database model.
Name |
Abhi |
Carry |
Stuart – 9/C2, BC Street, India |
Rosy |
Keys
In database management systems (DBMS), keys are used to uniquely identify records within a database table. They ensure data integrity and support efficient data retrieval and manipulation. There are different types of keys in DBMS, including:
- Primary Key: A primary key is a unique identifier for each record in a table. It ensures that there are no duplicate values and that each record can be uniquely identified. A primary key can consist of one or more columns in a table.
- Candidate Key: A candidate key is a set of attributes (columns) that can uniquely identify a record in a table. It is similar to a primary key but may not have been designated as the primary key.
- Foreign Key: A foreign key establishes a relationship between two tables in a relational database. It refers to the primary key of another table, creating a link between the two tables. The foreign key ensures referential integrity and maintains the relationships between tables.
- Unique Key: A unique key ensures that the values in a column (or a set of columns) are unique and not duplicated within a table. Unlike the primary key, a unique key can allow NULL values.
- Composite Key: A composite key is a key that consists of two or more columns in a table. Together, these columns uniquely identify a record. Individually, the columns may not be unique, but their combination makes them unique.
-
Super Key: A super key is a set of attributes that can uniquely identify a record in a table. It may contain more attributes than necessary to uniquely identify a record.
Example:
Employee ID | FirstName | Last Name |
01 | Aman | Johnson |
02 | Tarry | Alex |
03 | Carry | Paine |
Integrity constraints
Every relation in a relational database model should abide by or follow a few constraints to be a valid relation, these constraints are called as Relational Integrity Constraints.
The three main Integrity Constraints are:
- Key Constraints
- Domain Constraints
- Referential integrity Constraints
- Entity integrity Constraints
Key Constraints
We store data in tables, to later access it whenever required. In every table one or more than one attributes together are used to fetch data from tables. The Key Constraint specifies that there should be such an attribute(column) in a relation(table), which can be used to fetch data for any tuple(row).
The Key attribute should never be NULL or same for two different row of data.
For example, in the Employee table we can use the attribute ID to fetch data for each of the employee. No value of ID is null and it is unique for every row, hence it can be our Key attribute.
Domain Constraint
Domain constraints refers to the rules defined for the values that can be stored for a certain attribute.
Like we explained above, we cannot store Address of employee in the column for Name.
Similarly, a mobile number cannot exceed 10 digits.
Referential Integrity Constraint
We will study about this in detail later. For now remember this example, if I say Supriya is my girlfriend, then a girl with name Supriya should also exist for that relationship to be present.
If a table reference to some data from another table, then that table and that data should be present for referential integrity constraint to hold true.
Entity integrity Constraints
Entity Integrity Constraint is used to ensure the uniqueness of each record or row in the data table. There are primarily two types of integrity constraints that help us in ensuring the uniqueness of each row, namely, UNIQUE constraint and PRIMARY KEY constraint.
The unique key helps in uniquely identifying a record in the data table. It can be considered somewhat similar to the Primary key as both of them guarantee the uniqueness of a record. But unlike the primary key, a unique key can accept NULL values and it can be used on more than one column of the data table.
Schema Architecture
The three-schema architecture divides the database into three-level to create a separation between the physical database and the user application. In simple words, this architecture hides the details of physical storage from the user. The database administrator (DBA) should be able to change the structure of database storage without affecting the user’s view.
This architecture contains three layers or levels of the database management system:
- External level
- Conceptual level
- Internal level
Three Schema Architecture of DBMS
- External or View level: This is the highest level of database abstraction. External or view level describes the actual view of data that is relevant to the particular user. This level also provides different views of the same database for a specific user or a group of users. An external view provides a powerful and flexible security mechanism by hiding the parts of the database from a particular user.
- Conceptual or Logical level: The conceptual level describes the structure of the whole database. This level acts as a middle layer between the physical storage and user view. It explains what data to be stored in the database, what relationship exists among those data, and what the datatypes are. There is only one conceptual schema per database.
Database administrator and the programmers work at this level. This level does not provide any access or storage details but concentrates on the relational model of the database. The conceptual schema also includes features that specify the checks to retain integrity and consistency.
- Internal or Physical level: This is the lowest level of database abstraction. It describes how the data is actually stored in the database and provides methods to access data from the database. It allows viewing the physical representation of the database on the computer system. The interface between the conceptual schema and the internal schema identifies how an element in the conceptual schema is stored and how it may be accessed.
If there is any change in the internal or physical schema, it needs to be addressed to the interface between the conceptual and internal schema. But there is no need to change in the interface of a conceptual and external schema. It means that the changes in physical storage devices such as hard disks, and the files organized on storage devices, are transparent to application programs and users.
Data independence
A database system normally contains a lot of data in addition to users’ data. For example, it stores data about data, known as metadata, to locate and retrieve data easily. It is rather difficult to modify or update a set of metadata once it is stored in the database. But as a DBMS expands, it needs to change over time to satisfy the requirements of the users. If the entire data is dependent, it would become a tedious and highly complex job.
Logical Data Independence
Logical data is data about database, that is, it stores information about how data is managed inside. For example, a table (relation) stored in the database and all its constraints, applied on that relation.
Logical data independence is a kind of mechanism, which liberalizes itself from actual data stored on the disk. If we do some changes on table format, it should not change the data residing on the disk.
Physical Data Independence
All the schemas are logical, and the actual data is stored in bit format on the disk. Physical data independence is the power to change the physical data without impacting the schema or logical data.
For example, in case we want to change or upgrade the storage system itself − suppose we want to replace hard-disks with SSD − it should not have any impact on the logical data or schemas.