0% found this document useful (0 votes)
9 views

UNIT-2 DBMS-1

The document introduces the Relational Model (RM) for database management, explaining its structure of inter-related tables, terminology, and advantages such as structural independence and conceptual simplicity. It also discusses integrity constraints that maintain data accuracy and consistency, detailing various types like domain, referential, and key constraints. Additionally, it provides syntax examples for creating tables with different constraints in a database.

Uploaded by

Shruthi Kirthana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

UNIT-2 DBMS-1

The document introduces the Relational Model (RM) for database management, explaining its structure of inter-related tables, terminology, and advantages such as structural independence and conceptual simplicity. It also discusses integrity constraints that maintain data accuracy and consistency, detailing various types like domain, referential, and key constraints. Additionally, it provides syntax examples for creating tables with different constraints in a database.

Uploaded by

Shruthi Kirthana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT-2

INTRODUCTION TO RELATIONAL MODEL


 The Relational Model(RM) for database management is an approach to logically represent and manage the data
stored in a database.
 In this model, the data is organized into a collection of two-dimensional inter-related tables, also known
as relations.
 Each relation is a collection of columns and rows, where the column represents the attributes of an entity and the rows
(or tuples) represents the records.
Terminologies used in Relational Model
•Tables: relations are saved in the table format. A table has two properties rows and columns
•Attribute: columns represent as attributes
•Tuple: A Row represent as Tuple
•Relation Schema: A relation schema represents the name of the relation with its attributes.
•Degree: The total number of attributes which in the relation is called the degree of the relation.
•Cardinality: Total number of rows present in the Table.
•Column: The column represents the set of values for a specific attribute.
•Relation instance: The set of tuples of a relation at a particular instance of time is called as relation instance.
Advantages of Relational Model

•Structural Independence: Structural independence is an ability that allows us to make changes in one database structure
without affecting other. The relational model have structural independence. Hence making required changes in the database is
convenient in relational database model.
•Conceptual Simplicity: The relational model allows the designer to simply focus on logical design and not on physical
design. Hence relational models are conceptually simple to understand.
•Query Capability: Using simple query language (such as SQL) user can get information from the database or designer can
manipulate the database structure.
•Easy design, maintenance and usage: The relational models can be designed logically hence they are easy to maintain and
use.

Disadvantages of Relational Model


•Relational model requires powerful hardware and large data storage devices.
•May lead to slower processing time.
•Poorly designed systems lead to poor implementation of database systems.
Integrity constraint over relations in DBMS

 Integrity constraints are rules that help to maintain the accuracy and consistency of data in a database.

For example, a simple integrity constraint in DBMS might state that all students must have a valid Roll Number.
This would prevent someone from accidentally entering an invalid roll number into the database.

 Integrity constraints can also be used to enforce relationships between tables.

For example, if a student can only have one aadhaar number, then an integrity constraint can be used to ensure that
only one aadhaar number is entered for each student.
Different types of Integrity Constraints
•Domain Constraint
•Entity Integer Constraint
•Referential Integrity Constraint
•Key Constraints

Domain Constraint
A domain constraint is a restriction on the values that can be stored in a column. Strings, character, time, integer, currency,
date etc. Are examples of the data type of domain constraints.
example, if you have a column for "age" domain integrity constraints in DBMS would ensure that only integer values can be
entered into that column. This ensures that only valid data is entered into the database.
Syntax
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... PRIMARY KEY(column) );

Referential Integrity Constraint


A referential integrity constraint is a restriction on how foreign keys can be used. A foreign key is a column in one table
that references a primary key in another table.
For example, let's say you have a table of Students and a table of Marks. The "roll_number" column in the Marks table
would be a foreign key that references the "roll_number" column in the Students table.

Syntax
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... FOREIGN KEY (column) REFERENCES table_name1(column) );

Key Constraints
A key constraint is a rule that defines how data in a column(s) can be stored in a table. A key is composed of one or more
columns whose values uniquely identify each row in the table. There are several different types of key constraints in
DBMS, each with its own specific purpose.
1. Unique Key

A unique key refers to a column or a set of columns that identify every record uniquely in a table. All the values in this key
would have to be unique. values of a unique key won’t allow duplicate values and it is only capable of having one null value.

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... UNIQUE (column) );

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... CONSTRAINT constraint_name
UNIQUE(column) );

2. Primary
Key
The primary key refers to a column of a table that helps us identify all the records uniquely present in that table. Any table can
consist of only a single primary key constraint. values of a primary key won’t allow null value or a duplicate values.

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... CONSTRAINT constraint_name PRIMARY KEY(column) );
3. Foreign Key

We use a foreign key to establish relationships between two available tables. The foreign key would require every value
present in a column/set of columns to match the referential table’s primary key. A foreign key helps us to maintain data as
well as referential integrity.
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... CONSTRAINT
constraint_name FOREIGN KEY (column) REFERENCES table_name1(column) );

4. Composite Key
The composite key refers to a set of multiple attributes that help us uniquely identify every tuple present in a table. The
attributes present in a set may not be unique whenever we consider them separately. Thus, when we take them all together, it
will ensure total uniqueness.
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... CONSTRAINT constraint
name UNIQUE(column, column) );
5. Super Key
A super key refers to the set of all those keys that help us uniquely identify all the rows present in a table. It means that all of
these columns present in a table that can identify the columns of that table uniquely act as the super keys.

6. Candidate Key
The candidate keys refer to those attributes that identify rows uniquely in a table. In a table, we select the primary key from a
candidate key. Thus, a candidate key has similar properties as that of the primary keys that we have explained above. In a table,
there can be multiple candidate keys.
7. Alternate Key

As we have stated above, any table can consist of multiple choices for the primary key. But, it can only choose one. Thus, all
those keys that did not become a primary key are known as alternate keys.
CHECK Constraint
The CHECK constraint is used to limit the value range that can be placed in a column. If you define a CHECK constraint
on a column it will allow only certain values for this column. If you define a CHECK constraint on a table it can limit the
values in certain columns based on values in other columns in the row.
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... CONSTRAINT
constraint_name CHECK (condition) );

Example: CREATE TABLE students ( ID int, LastName varchar(30), FirstName varchar(30), Age int, CONSTRAINT
con_age CHECK (Age>=18) );

DEFAULT Constraint
The DEFAULT constraint is used to set a default value for a column. The default value will be added to all new records, if no
other value is specified.
The DEFAULT constraint can also be used to insert system date, by using functions like GETDATE().
CREATE TABLE table_name ( column1 datatype, column2 datatype DEFAULT 'value', column3 datatype DEFAULT
GETDATE(), .... );
CREATE TABLE students ( ID int, LastName varchar(30), FirstName varchar(30), Age int DEFAULT 18, joining_date
DEFAULT GETDATE() );

You might also like