The document discusses topics related to modifying databases, including deletion, insertion, and updates using SQL statements. It also covers join expressions, views, and integrity constraints. The next lecture will cover SQL data types, schemas, and accessing SQL from programming languages.
The document discusses topics related to modifying databases, including deletion, insertion, and updates using SQL statements. It also covers join expressions, views, and integrity constraints. The next lecture will cover SQL data types, schemas, and accessing SQL from programming languages.
The document discusses topics related to modifying databases, including deletion, insertion, and updates using SQL statements. It also covers join expressions, views, and integrity constraints. The next lecture will cover SQL data types, schemas, and accessing SQL from programming languages.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Review of Previous Class Topic
• Aggregate Functions – Nested Sub queries
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Topic Outcome
• Modification of Database – Join Expressions –
Views – Integrity Constraints
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Modification of Database
We have restricted our attention until now to the extraction of
information from the database. Now, we show how to add, remove, or change information with SQL.
Deletion : A delete request is expressed in much the same
way as a query. We can delete only whole tuples; we cannot delete values on only particular attributes. SQL expresses a deletion by
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Modification of Database
Delete all tuples in the instructor relation pertaining to
instructors in the Finance department
Delete all instructors with a salary between $13,000 and
$15,000
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Modification of Database
Delete all tuples in the instructor relation for those instructors
associated with a department located in the Watson building
This delete request first finds all departments located in
Watson, and then deletes all instructor tuples pertaining to those departments
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Insertion
To insert data into a relation, we either specify a tuple to be
inserted or write a query whose result is a set of tuples to be inserted. Obviously, the attribute values for inserted tuples must be members of the corresponding attribute’s domain.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Insertion
Suppose that we want to make each student in the Music
department who has earned more than 144 credit hours, an instructor in the Music department, with a salary of $18,000. We write:
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Updates
In certain situations, we may wish to change a value in a tuple
without changing all values in the tuple. For this purpose, the update statement can be used. As we could for insert and delete, we can choose the tuples to be updated by using a query.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Updates
SQL provides a case construct that we can use to perform
both the updates with a single update statement, avoiding the problem with the order of updates.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Updates
The general form of the case statement is as follows
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Join Expressions
A JOIN clause is used to combine rows from two or more
tables, based on a related column between them.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Nested Subqueries
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Views
We define a view in SQL by using the create view command.
To define a view, we must give the view a name and must state the query that computes the view. The form of the create view command is:
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Views
We define a view in SQL by using the create view command.
To define a view, we must give the view a name and must state the query that computes the view. The form of the create view command is:
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Integrity Constraints
Integrity constraints ensure that changes made to the
database by authorized users do not result in a loss of data consistency.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Try it yourself
• Create table department with following fields
department name, building, budget.
• In this table department name should be
primary key
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Solution
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Try it yourself
• Create table course with following field course
id, title, department name, credits.
• In this table Course id should be primary key
• And also, department name should be foreign key.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Solution
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Question
Expand DML __________________
a. Data-Definition Language b. Data-Manipulation Language c. Data Maintain Language d. All of these
What is a foreign key?
A. A foreign key is a primary key of a relation which is an attribute in another relation B. A foreign key is a superkey of a relation which is an attribute in more than one other relations C. A foreign key is an attribute of a relation that is a primary key of another relation.. D. A foreign key is the primary key of a relation that does not occur anywhere else in the schema
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Evaluation Questionnaires
1. What is SQL? 2. What is DML?
3. What is Primary Key?
4. What foreign Key?
5. Define Check Constraints.
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23
Next topic for Lect. 12
• SQL Data types and Schemas –
Accessing SQL from a Programming Language
21BCT3DA - Discipline Specific Core - RDBMS | ODD 2022-23