0% found this document useful (0 votes)
20 views18 pages

Database Design and Key Constraints

C programming

Uploaded by

xzbunny1991
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

Topics covered

  • Entity Integrity,
  • Null Values,
  • Update Operation,
  • Data Organization,
  • Data Insertion,
  • Database Performance,
  • Unique Key,
  • Data Integrity,
  • Insert Operation,
  • Database Security
0% found this document useful (0 votes)
20 views18 pages

Database Design and Key Constraints

C programming

Uploaded by

xzbunny1991
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

Topics covered

  • Entity Integrity,
  • Null Values,
  • Update Operation,
  • Data Organization,
  • Data Insertion,
  • Database Performance,
  • Unique Key,
  • Data Integrity,
  • Insert Operation,
  • Database Security

DATABASE DESIGN

Presenting by: Sneha C


Relational database
 A RDBMS is a database that organizes data in tables or relations
of columns & rows and shows how different data structures
related to each other
 Here the data is structured in the form of tables, Rows, Columns,
Primary key, Foreign key, Relationships, Normalization
 Customer table:

C-id C-Name Billing Shipping


address address

Order table:
O-id C-id Order date Shipping date
Relational database keys

 Types:
1. Super key
2. Candidate key
3. Primary key
4. Alternate key
5. Unique key
6. Composite key
7. Foreign key
.

Super key:
 It is a set of one or more attributes in a table that can be
uniquely identify a row in that table. In other words, a super key
can uniquely distinguish every tuple(row) in a relation(table)
 A super key can consists of a single attribute or a combination of
attributes. However, it may contain unnecessary attributes

ID Name SSN Salary Phone no. email


101 Mary 123456789012 30000 7018345643 mary@123
102 John 981234567034 25000 6360123404 john@453
103 Mary 543126754897 45000 9900765488 my@342
104 Raj 301276325678 70000 7019345977 raj@987
.

Candidate key:
 The minimal super keys are called Candidate keys. It means a set
of one or more columns in a table that can be uniquely identify a
record, but it contains no unnecessary attributes
 There can be multiple candidate keys in a table, but only one of
them is selected to be the primary key
.

Primary key:
 It is the specific type of candidate key that is chosen to uniquely
identify each record in a table
 It ensures that no duplicate or Null values exist for the primary
key column, making it the main unique identifier for records in
the table
 Student Table:

Stud_id Stud_name Email

101 Priya pri@124


102 Preethi Preethi@190
.

Alternate key:
 The candidate key other than primary key

Unique key:
 It is a database constraint that ensures the values in a column(s)
are unique across all rows in the table
 Unlike a primary key, a unique key can accept one null value, but
all other non-null values must be distinct
Composite key:
.

 It is a type of database key that consists of two or more columns


used together to uniquely identify a row in a table
 Unlike a primary key made up of a single column, a composite
key combines multiple columns to ensure that each combination
of values in these columns is unique across the table
.

Foreign key:
 Is a column or a set of columns in a database table that
establishes a link between the data in two tables.
 The foreign key in one table refers to the primary key in another
table
 This relation enforces the referential integrity
 Customers
cust_id cust_name
1001 John
1002 Smith

Orders
Order-id Cust-id Order-date
1 1001 24-11-2024
2 1002 25-11-2024
DEALING WITH
CONSTRAINT VIOLATIONS

 .
.r

 Here we will learn about the violations that can


occur on a database as a result of any changes
made in the relation
 There are mainly 3 operations that have the ability
to change the state of relations, these operations
are:
1. Insert operation
2. Delete operation
3. Update(Modify) operation
Insert Operation:
.
 To insert new tuples in a relation in the database
 On inserting the tuples in the relation, it may cause
violation of the constraints in the following way:
 Domain constraint:
• Domain constraint gets violated only when a given
value to the attribute does not appear in the
corresponding domain or in case it is not of the
appropriate datatype
• EmployeeName
Emp id
Table Age Phone DNo
101 Aisha 24 656474904 1
3
102 Bindu 25 658930130 2
8
103 Lakshmi 24 901463892 A
.

Department Table:
DNo Dname Location
1 CSE Banglore
2 MECH Banglore
 Entity Integrity constraint:

• On inserting NULL values to any part of the primary


key of a new tuple in the relation can cause violation
of the entity integrity constraint
• Employee Table
.

 Key constraints:
• On inserting a value in the new tuple of a relation
which is already existing in another tuple of the
same relation, can cause violation of key constraints
• Employee Table:
 Referential integrity:
• On inserting a value in the foreign key of relation 1,
for which there is no corresponding value in the
Primary key which is referred to in relation 2, in
such case Referential integrity is violated
.

 Delete Operation:
 To delete some of the existing relation on the
database
 Referential integrity constraints:
• It causes violation only if the tuple in relation 1 is
deleted which is referenced by foreign key from
other tuples of table 2 in the database, if such
deletion t takes place then the values in the tuple of
the foreign key in table 2 will become empty, which
will eventually violate referential integrity constraint
 Update Operation:
 . To make changes in the value of some existing
tuples
.

THANK
YOU

Common questions

Powered by AI

The update operation can lead to constraint violations by modifying an attribute to a value that breaches domain, key, or referential integrity constraints . To prevent these violations, updates should be validated against existing constraints, ensuring values comply with domain requirements, maintain unique keys, and uphold referential integrity by ensuring foreign keys still correspond to valid primary keys .

Insert operations can violate domain constraints if values do not appear in the specified domain or are of the wrong datatype . Entity integrity can be violated if NULL values are inserted into columns that make up the primary key . Key constraints can be violated if duplicate values are inserted where uniqueness is required . Referential integrity is violated if a foreign key value is inserted without a corresponding primary key . Mitigations include enforcing data types, checking for uniqueness, and ensuring that any foreign key insertion has a matching primary key .

A super key is a set of one or more attributes that can uniquely identify a row in a table, but it may contain unnecessary attributes . A candidate key is a minimal super key, meaning it uniquely identifies a record while having no unnecessary attributes . A primary key is a specific type of candidate key that is chosen to uniquely identify each record, ensuring no duplicate or null values exist in its column(s).

Composite keys can complicate database design and maintenance because they involve multiple columns, which can make indexing and querying less straightforward compared to single-column primary keys . They can also increase the complexity of joins across tables and may require careful planning to ensure that the combinations of columns indeed maintain uniqueness . Moreover, any change in composite key structure can significantly affect dependent database relationships and constraints .

Alternate keys serve as additional identifiers for table records beyond the primary key, providing alternative options for indexing and query optimization . They can be useful in situations where different fields or combinations of fields may need to be uniquely identified in various contexts. Alternate keys can be strategically chosen to facilitate efficient data retrieval and can serve as backup identifiers that enhance data accessibility and system resilience .

Referential integrity ensures that a foreign key in one table corresponds to a valid primary key in another table, thus enforcing a valid link between different tables . It helps maintain data integrity by preventing operations that would result in invalid or orphaned references, particularly during insertions and deletions .

Normalization organizes database tables by minimizing redundancy and dependency through structuring data into multiple related tables . During normalization, tables are often restructured to ensure that each table only contains data directly related to its primary key. This process involves identifying and using properly defined keys (super, candidate, primary, foreign) to establish relationships and enforce data integrity, thereby optimizing the database structure and improving efficiency .

A delete operation can impact referential integrity if it removes a record whose primary key is referenced by foreign keys in other tables, making those foreign key references invalid . Such violations can be avoided by using cascading delete operations, which automatically remove all related records in the child tables, or by setting the foreign key fields to NULL or a default value when the referenced record is deleted .

A composite key is a type of database key consisting of two or more columns used together to uniquely identify a row in a table, as opposed to a primary key that may consist of a single column . Composite keys should be used when a single column cannot uniquely identify a record, and the uniqueness can only be achieved through a combination of columns .

A unique key enforces uniqueness for all non-null values, allowing for a single null value in the column . This is because a unique key is meant to prevent duplicate entries but does not enforce the 'no null' constraint that is mandatory for primary keys, which ensures that every record is uniquely identifiable .

You might also like