Relational Model
Unit-2
Introduction to Relational Databases
• Relation database is a collection of tables having unique names.
• For example - Consider the example of Student table, Course table and
Admission table
Relational Model Concepts
Table or relation:
• In relational model, table is a collection of data items arranged in rows and
columns.
• The table cannot have duplicate data or rows.
• Below is an example of student table
Tuple or record or row:
Attribute or columns:
• It is a part of table that contains several records.
• Each record can be broken down into several small parts of data known as
attributes.
• For example the above table consists of four attributes such as RollNo, Name,
Marks and Phone
• Relation schema: A relation schema describes the structure of the relation, with
the name of the relation (i.e. name of table), its attributes and their names and
type.
Relational Model Concepts
Relation Instance: It refers to specific instance of relation i.e. containing a specific set of rows.
• For example - the following is a relation instance - which contains the records with marks
above 80.
Domain:
• For each attribute of relation, there is a set of permitted values called domain.
• For example - in above table, the domain of attribute Marks is set of all possible permitted
marks of the students.
• Similarly the domain of Name attribute is all possible names of students.
Relational Model Concepts
Atomic:
• The domain is atomic if elements of the domain are considered to be indivisible
units.
• For example in above Student table, the attribute Phone is non-atomic.
NULL attribute:
• A null is a special symbol, independent of data type, which means either
unknown or inapplicable.
• It does not mean zero or blank. For example - Consider a salary table that
contains NULL
Relational Model Concepts
Degree:
• It is nothing but total number of columns present in the relational database.
• In given Student table The degree is 4
Cardinality:
• It is total number of tuples present i in the relational database.
• In above given table the cardinality is 3
Keys
1) Super Key(SK):
• Keys are used to specify the tuples distinctly in the given relation
• Various types of keys used in relational model are - Superkey, Candidate Keys,
primary keys, foreign keys
• It is a set of one or more attributes within a table that can uniquely identify
each record within a table
• For example - Consider the Student table as follows,
Keys
• The Superkey can be represented as follows,
• [Link]
Keys
2) Candidate Key(CK):
• The candidate key is a subset of superset.
• Candidate key is a single attribute or least or minimal combination of attributes that uniquely
identify each record in the table.
• For example - in above given Student table, the candidate key is RegNo, (RollNo,Phone).
Keys
3) Primary Key(PK)
• The primary key is a candidate key chosen by the database designer to identify
the tuple in the relation uniquely.
• For example - Consider the following representation of primary key in the
student table
Keys
Rules for Primary Key
(i) The primary key may have one or more attributes.
(ii) There is only one primary key in the relation.
(iii) The value of primary key attribute can not be NULL.
(iv) The value of primary key attributes does not be NULL.
4) Alternate Key:
The alternate key is a candidate key which is not chosen by the database designer to uniquely
identify the tuples.
Keys
5) Foreign key:
Foreign key is a single attribute or collection of attributes in one table that refers to
the primary key of other table.
• Thus foreign keys refers to primary key.
• The table containing the primary key is called parent table and the table
containing foreign key is called child table.
Integrity Constraints
• Database integrity means correctness or accuracy of data in the database.
• A database may have number of integrity constraints.
• For example
(i) The Employee ID and Department ID must consists of two digits.
(ii) Every Employee ID must start with letter.
• The integrity constraints are classified based on the concept of primary key and
foreign key.
• Let us discuss the classification of constraints based on primary key and foreign
key as follows
Entity Integrity Rule
• This rule states that "In the relations, the value of attribute of primary key can
not be null".
• The NULL represents a value for an attribute that is currently unknown or is not
applicable for this tuple.
• The Nulls are always to deal with incomplete or exceptional data.
• The primary key value helps in uniquely identifying every row in the table.
• Thus if the users of the database want to retrieve any row from the table or
perform any action on that table, they must know the value of the key for that
row.
• Hence it is necessary that the primary key should not have the NULL value.
Referential Integrity Rule
• Referential integrity refers to the accuracy and consistency of data within a
relationship.
• In relationships, data is linked between two or more tables.
• This is achieved by having the foreign key (in the associated table) reference a
primary key value (in the primary or parent - table).
• Because of this, we need to ensure that data on both sides of the relationship
remain intact.
• The referential integrity rule states that "whenever a foreign key value is used it
must reference a valid, existing primary key in the parent table".
Example:
• Consider the situation where you have two tables Employees and Managers.
• The Employees table has a foreign key attribute entitled Managed By, which points
Advantages of Referential Integrity
i) Prevents the entry of duplicate data.
ii) Prevents one table from pointing to a nonexistent field in another table.
ii) Guaranteed consistency between "partnered" tables.
iii) Prevents the deletion of a record that contains a value referred to by a foreign
key in another table.
iv) Prevents the addition of a record to a table that contains a foreign key unless
there is a primary key in the linked table.
[Link]
Structured Query Language
SQL Fundamentals
• Structure Query Language(SQL) is a database query language used for storing and managing data in
Relational DBMS.
Various parts of SQL
• Data Definition Language(DDL): It consists of a set of commands for defining relation schema,
deleting relations, and modifying relation schemas.
• Data Manipulation Language(DML): It consists of set of SQL commands for inserting tuples into
relational schema, deleting tuples from or modifying tuples in databases.
• Integrity: The SQL DDL includes commands for specifying integrity constraints. These constraints
must be satisfied by the databases.
• View definition: The SQL DDL contains the commands for defining views for database.
• Transaction control: The SQL also includes the set of commands that indicate beginning and ending
of the transactions.
• Embedded SQL and Dynamic SQL: There is a facility of including SQL commands in the programming
languages like C,C++, COBOL or Java.
• Authorization: The SQL DDL includes the commands for specifying access rights to relations and
Structured Query Language
Data Abstraction
The Basic data types used in SQL
(1) char(n): For representing the fixed length character string this data type is used. For instance
to represent name, designation, coursename, we use this data type. Instead of char we can also
use character. The n is specified by the user.
(2) varchar(n): The varchar means character varying. That means - for denoting the variable
length character strings this data type is used. The n is user specified maximum character length.
(3) int: For representing the numeric values without precision, the int data type is used.
(4) numeric: For representing, a fixed point number with user-specified precision this data type is
used. The number consists of m digits plus sign k digits are to the right of precision. For instance
the numeric(3,2) allows 333.11 but it does not allow 3333.11
(5) smallint: It is used to store small integer value. It allows machine dependent subset of integer
type.
(6) real: It allows the floating point, double precision numbers.
(7) float(n): For representing the floating point number with precision of at least n digits this data
type is used.
Structured Query Language
Basic Schema Definition
• In this section, we will discuss various SQL commands for creating the schema
definition.
• There are three categories of SQL commands.
Structured Query Language
Data Definition Language
[Link]
[Link]
[Link]
Data Manipulation Language
[Link]
[Link]
[Link]
[Link]
Data Control Language
[Link]
[Link]
1. Creation
• A database can be considered as a container for tables and a table is a grid with
rows and columns to hold data.
• Individual statements in SQL are called queries.
• We can execute SQL queries for various tasks such as creation of tables, insertion
of data into the tables, deletion of record from table, and so on.
Step 1:
create database database_name;
Example
create database Person _DB
Step 2:
create table table name ( Col1_name datatype, col2 _name datatype, ……
create table student
( stud_name varchar(20),
stud_id int(3),
DOB varchar(15),
branch varchar(10),
DOJ varchar(15), );
create table course
(course_name varchar(20),
course_id int(5),
stud_id int(3),
facult_name varchar(20),
faculty_id varchar(5),
2. Insertion
• The insert command is used to insert the values into database tables. Using the
select command, the database values can be displayed.
• Syntax
insert into table_name (col1, col2,...,coln)
values (value1,value,...., valuen)
Example
insert into Student(stud_name,stud_id,DOB,branch,DOJ)
values('AAA',11,'01-10-1999', 'computers','5-3-2018')
3. Select
• The Select statement is used to fetch the data from the database table.
• The result returns the data in the form of table.
• These result tables are called result sets.
• We can use the keyword DISTINCT. It is an optional keyword indicating that the
answer should not contain duplicates.
• Normally if we write the SQL without DISTINCT operator then it does not
eliminate the duplicates.
Syntax
select col1, col2, ...,coln from table_name;
Example
select AdharNo, FirstName, Address, City from person_details
4. Where Clause
The WHERE command is used to specify some condition. Based on this condition
the data present in the table can be displayed or can be updated or deleted.
Syntax
select col1,col2, ...,coln
from table_name
where condition;
Example:
select adharno
from person_details
where city='pune';
5. Update
• For modifying the existing record of a table, update query is used.
Syntax
update table name
set col1-value1, col2-value2,...
where condition;
Example
update rerson_details set city 'chennai’ where adharno=333;
6. Deletion
• We can delete one or more records based on some condition
• Syntax
delete from table_name where condition;
• We can delete all the records from table. But in this deletion, all the records get
deleted without deleting table. For that purpose the SQL statement will be
delete from person_details;
7. Logical Operators
• Using WHERE clause we can use the operators such as AND, OR and NOT.
• AND operator displays the records if all the conditions that are separated using AND operator
are true.
• OR operator displays the records if any one of the condition separated using OR operator is
true.
• NOT operator displays a record if the condition is NOT TRUE.
Syntax of AND
select col1, col2, ...
from table_name
where condition1 AND condition2 AND condition3...;
Example of AND
select adharno, firstname, city
from person_details
Syntax of OR
select col1, col2, ...
from table_name
where condition1 OR condition2 OR condition3 ...;
Example of OR
select adharno, firstname, city
from person_details
where city='pune' or city='mumbai’;
Syntax of NOT
select col1, col2, ...
from table_name
where not condition;
Example of NOT
select adharno, firstname, city
from person_details
where not city=‘pune';
8. Order By Clause
• Many times we need the records in the table to be in sorted order.
• If the records are arranged in increasing order of some column then it is called
ascending order.
• If the records are arranged in decreasing order of some column then it is called
descending order.
• For getting the sorted records in the table we use ORDER BY command.
• The ORDER BY keyword sorts the records in ascending order by default.
Syntax
select col1, col2,...,coln
from table_name
order by col1,col2.... asc | desc
Example
select *
from person_details
order by adharno desc;
9. Alteration
• There are SQL command for alteration of table.
• That means we can add new column or delete some column from the table
using these alteration commands
Syntax for Adding columns
alter table table_name add column_name datatype;
Example
alter table customers add email varchar(30);
Syntax for Deleting columns
alter table table_name
drop column column name;
Example
alter table customers drop column address;
10. Defining Constraints
• We can specify rules for data in a table.
• When the table is created at that time we can define the constraints.
• The constraint can be column level i.e. we can impose constraint on the column and table
level
• We can impose constraint on the entire table.
i) Primary key:
• The primary key constraint is defined to uniquely identify the records from the table.
• The primary key must contain unique values. Hence database designer should choose
primary key very carefully.
For example
• Consider that we have to create a person_details table with AdharNo, FirstName,
MiddleName, LastName, Address and City.
• Now making AdharNo as a primary key is helpful here as using this field it becomes easy to
create table person_details (
adharno int, firstname varchar(20), middlename varchar(20), lastname
varchar(20), address varchar(30), city varchar(10), primary key(adharno));
•We can create a composite key as a primary key using CONSTRAINT keyword.
•For example
create table person_details (
adharno int not null, firstname varchar(20), middlename varchar(20), lastname
varchar(20) not null, address varchar(30), city varchar(10), constraint
pk_person_details primary key(adharno, lastname));
(ii) Foreign Key
• Foreign key is used to link two tables.
• Foreign key for one table is actually a primary key of another table.
• The table containing foreign key is called child table and the table containing
candidate primary key is called parent key.
Employee Table:
Dept Table:
• Notice that the "EmpID" column in the "Dept" table points to the "EmpID"
column in the "Employee" table.
• The "EmpID" column in the "Employee" table is the PRIMARY KEY in the
"Employee" table.
• The "EmpID" column in the "Dept" table is a FOREIGN KEY in the "Dept" table.
• The FOREIGN KEY constraint is used to prevent actions that would destroy links
between tables.
• The FOREIGN KEY constraint also prevents invalid data from being inserted into
the foreign key column, because it has to be one of the values contained in the
table it points to.
• The purpose of the foreign key constraint is to enforce referential integrity but
there are also performance benefits to be had by including them in your
database design.
• The table Dept can be created as follows with foreign key constraint.
create table dept (
deptid int
deptname varchar(20),
empid int,
primary key(deptid),
foreign key (empid)
references employee(empid)
);
(iii) Unique
• Unique constraint is used to prevent same values in a column.
• In the EMPLOYEE table, for example, you might want to prevent two or more
employees from having an identical designation.
• Then in that case we must use unique constraint.
• We can set the constraint as unique at the time of creation of table, or if the table is
already created and we want to add the unique constraint then we can use ALTER
command.
For example -
create table EMPLOYEE( EmpID INT NOT NULL, Name VARCHAR (20) NOT NULL,
Designation VARCHAR(20) NOT NULL UNIQUE, Salary DECIMAL (12, 2),
PRIMARY KEY (EmpID));
• If table is already created then also we can add the unique constraint as follows,
(iv) NOT NULL
• By default the column can have NULL values.
• NULL means unknown values.
• We can set the column values as non NULL by using the constraint NOT NULL.
• For example
create table EMPLOYEE( EmpID int not null, name varchar (20) not null, designation
varchar(20) not null, salary decimal (12, 2) not null, primary key (EmpID));
(v) CHECK
• The CHECK constraint is used to limit the value range that can be placed in a
column.
• For example
create table parts ( Part_no int primary key, description varchar(40), price
decimal(10, 2) not null check(cost > 0));
(vi) IN operator
• The IN operator is just similar to OR operator.
• It allows to specify multiple values in WHERE clause.
Syntax
SELECT col1,col2,....
FROM table_name
WHERE column-name IN (value1, value2,...);
Example
SELECT FROM Employee
WHERE empID IN (1, 3);
Basic Structure of SQL Queries
SELECT-FROM-WHERE
Syntax:
SELECT[DISTINCT] target-list
FROM Relation-list
WHERE Qualification
• SELECT: This is one of the fundamental query command of SQL. It is similar to the
projection operation of relational algebra. It selects the attributes based on the
condition described by WHERE clause.
• FROM: This clause takes a relation name as an argument from which attributes are
to be selected/projected. In case more than one relation names are given, this
clause corresponds to Cartesian product.
• WHERE: This clause defines predicate or conditions, which must match in order to
qualify the attributes to be projected.
• Relation-list: A list of relation names(tables)
• Target-list: A list of attributes of relations from relation list(tables)
• Qualification: Comparisons of attributes with values or with other attributes
combined using AND, OR and NOT.
• DISTINCT is an optional keyword indicating that the answer should not contain
duplicates. Normally if we write the SQL without DISTINCT operator then it does
Queries on Multiple Relations
• Many times it is required to access multiple relations (tables) to operate on some
information.
• For example consider two tables as Student and Reserve.
Query:
• Find the names of students who have reserved the books with book isbn
select [Link], [Link]
from Student, Reserve
Use of SQL Join
• The SQL Joins clause is used to combine records from two or more tables in a
database.
• A JOIN is a means for combining fields from two tables by using values common
to each.
• Example: Consider two tables for using the joins in SQL.
• Note that cid is common column in following tables.
1) Inner Join:
• The most important and frequently used of the joins is the INNER JOIN. They are
also known as an EQUIJOIN.
• The INNER JOIN creates a new result table by combining column values of two
alqutul no tables (Table1 and Table2) based upon the join-predicate.
• The query compares each row of tablel with each row of Table2 to find all pairs of
rows which satisfy the join-predicate.
• When the join-predicate is satisfied, column values for each matched pair of rows
of A and B are combined into a result row. It can be represented as:
Syntax: The basic syntax of the INNER JOIN is as follows,
SELECT Table1.column1, Table2.column2... FROM Table1 INNER JOIN Table2
ON Table1.common_field = Table2.common_field;
• Example: For above given two tables namely Student and City, we can apply
inner join.
• It will return the record that are matching in both tables using the common
column cid.
select * from student Inner Join City on [Link]=[Link]
The result will be
2) Left Join:
• The SQL LEFT JOIN returns all rows from the left table, even if there are no
matches in the right table.
• This means that if the ON clause matches 0 (zero) records in the right table; the
join will still return a row in the result, but with NULL in each column from the
right table.
• This means that a left join returns all the values from the left table, plus
matched values from the right table or NULL in case of no matching join
predicate.
• It can be represented as,
Syntax: The basic syntax of a LEFT JOIN is as follows.
SELECT Table1.column1, Table2.column2...
FROM Table1 LEFT JOIN Table2
ON [Link] field [Link] field;
• Example: For above given two tables namely Student and City, we can apply Left
join.
• It will Return all records from the left table, and the matched records from the
right table using the common column cid. The query will be
select * from student Left Join City on [Link]=[Link]
3) Right Join:
• The SQL RIGHT JOIN returns all rows from the right table, even if there are no
matches in the left table.
• This means that if the ON clause matches 0 (zero) records in the left table; the
join will still return a row in the result, but with NULL in each column from the left
table.
• This means that a right join returns all the values from the right table, plus
matched values from the left table or NULL in case of no matching join predicate.
• It can be represented as follows:
• Syntax: The basic syntax of a RIGHT JOIN is as follows,
SELECT Table1.column1, Table2.column2...
FROM Table1 RIGHT JOIN Table2
ON Table1.common_field = Table2.common_field;
• Example: For above given two tables namely Student and City, we can apply
Rightjoin.
• It will return all records from the right table, and the matched records from the
left table using the common column cid. The query will be,
select * from student Right Join City on [Link]=[Link]
4) Full Join:
• The SQL FULL JOIN combines the results of both left and right outer joins.
• The joined table will contain all records from both the tables and fill in NULLS for
missing matches on either side.
• It can be represented as
• Syntax: The basic syntax of a FULL JOIN is as follows
SELECT Table1.column1, Table2.column2...
FROM Table1 FULL JOIN Table2 ON Table1.common_field = Table2.common_field;
Example:
• For above given two tables namely Student and City, we can apply Full join.
• It will return returns rows when there is a match in one of the tables using the
common column cid.
• he query will be -
select * from Student Full Join City on [Link]=[Link]
String Operations
• For string comparisons, we can use the comparison operators =, <, >,<,>=> with
the ordering of strings determined alphabetically as usual.
• SQL also permits a variety of functions on character strings such as concatenation
suing operator, extracting substrings, finding length of string, converting strings to
upper case(using function upper(s)) and lowercase(using function lower(s)),
removing spaces at the end of string(using function(trim(s)) and so on.
• Pattern matching can also be performed on strings using two types of special
characters -
• Percent(%): It matches zero, one or multiple characters
• Underscore(_): The _ character matches any single character.
• The percentage and underscore can be used in combinations.
• Patterns are case sensitive. That means upper case characters do not match
For instance:
• 'Data%' matches any string beginning with "Data", For instance it could be with
a blen "Database", "DataMining","DataStructure"
• ' _ _ _' matches any string of exactly three characters.
• ' _ _ _%’ matches any string of at least length 3 characters.
• The LIKE clause can be used in WHERE clause to search for specific patterns.
• For example - Consider following Employee Database
Set Operations
1) UNION: To use this UNION clause, each SELECT statement must have
i) The same number of columns selected
ii) The same number of column expressions
iii) The same data type
iv) Have them in the same order
Syntax
SELECT column1 [, column2]
FROM table1 [, table2 ]
[WHERE condition]
UNION
SELECT column1 [, column2 ]
FROM table1 [, table2 ]
• Consider Following relations ,
Example:
• Find the names of the students who have reserved the 'DBMS' book or 'OS'
Book
• The query can then be written by considering the Student, Reserve and Book
table as
SELECT [Link]
FROM Student S, Reserve R, Book B
WHERE [Link] AND [Link]=[Link] AND [Link]='DBMS'
UNION
SELECT [Link]
FROM Student S, Reserve R, Book B
WHERE [Link] AND [Link]=[Link] AND [Link]='OS'
2) INTERSECT: The common entries between the two tables can be represented
with the help of Intersect operator. It replaces the AND operator in the query.
Syntax
The basic syntax of a INTERSECT clause is as follows --
SELECT column1 [, column2]
FROM table1 [, table2 ]
[WHERE condition]
INTERSECT
SELECT column1 [, column2]
FROM table1 [, table2 ]
[WHERE condition]
Example:
• Find the students who have reserved both the 'DBMS' book and 'OS' Book
• The query can then be written by considering the Student, Reserve and Book
table as
SELECT [Link], [Link]
FROM Student S, Reserve R, Book B
WHERE [Link] AND [Link]=[Link] AND [Link]='DBMS’
INTERSECT
SELECT [Link]
FROM Student S, Reserve R, Book B
WHERE [Link] AND [Link]=[Link] AND [Link]='OS'
3) EXCEPT:
• The EXCEPT clause is used to represent the set-difference in the query.
• This query is used to represent the entries that are present in one table and not in
other.
Syntax:
The basic syntax of a EXCEPT clause is as follows -
SELECT column1 [, column2 |
FROM table1 [, table2 ]
[WHERE condition]
EXCEPT
SELECT column1 [, column2]
FROM table1 [, table2]
Example:
• Find the students who have reserved both the 'DBMS' book but not reserved
'OS' Book
• The query can then be written by considering the Student, Reserve and Book
table as
SELECT [Link], [Link]
FROM Student S, Reserve R, Book B
WHERE [Link]=[Link] AND [Link]=[Link] AND [Link]='DBMS’
EXCEPT
SELECT [Link]
FROM Student S, Reserve R, Book B
WHERE [Link]=[Link] AND [Link]=[Link] AND
Aggregate Functions
• An aggregate function allows you to perform a calculation on a set of values to
return a single scalar value.
• SQL offers five built-in aggregate functions:
1. Average: avg
2. Minimum: min
3. Maximum : max
4. Total: sum
5. Count: count
1. Basic Aggregation
• The aggregate functions that accept an expression parameter can be modified by the
keywords DISTINCT or ALL.
• If neither is specified, the result is the same as if ALL were specified.
Syntax of all the Aggregate Functions
AVG([ DISTINCT | ALL ] expression)
COUNT(*)
COUNT([ DISTINCT | ALL | expression)
MAX( | DISTINCT | ALL ] expression)
MIN([ DISTINCT | ALL ] expression)
2. Use of Group By and Having Clause
(i) Group By:
• The GROUP BY clause is a SQL command that is used to group rows that have the same values.
• Optionally it is used in conjunction with aggregate functions.
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
(ii) Order By
The general syntax with ORDER BY is
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column name(s)
Query: Find the total marks of each student in each city
SELECT SUM(marks), city
FROM Student
GROUP BY city
Output
(ii) Having:
• HAVING filters records that work on summarized GROUP BY results.
• HAVING applies to summarized group records, whereas WHERE applies to been
individual records.
• Only the groups that meet the HAVING criteria will be returned.
• HAVING requires that a GROUP BY clause is present.
• WHERE and HAVING can be in the same query.
Syntax:
SELECT column-names
FROM table-name
WHERE condition
GROUP BY column-names
Query: Find the total marks of each student in the city named 'Pune' and 'Mumbai'
only
SELECT SUM(marks), city
FROM Student
GROUP BY city
HAVING city IN('Pune', 'Mumbai')
Output
• The result will be as follows-
Nested Queries
• In nested queries, a query is written inside a query.
• The result of inner query is used in execution of outer query.
• There are two types of nested queries:
i) Independent Query:
• In independent nested queries, query execution starts from innermost query to
outermost queries.
• The execution of inner query is independent of outer query, but the result of
inner query is used in execution of outer query.
• Various operators like IN, NOT IN, ANY, ALL etc are used in writing independent
nested queries.
• For example - Consider three tables namely Student, City and Student_City as
follows-
• Example 1
• If we want to find out sid who live in city 'Pune' or 'Chennai’.
• We can then write independent nested query using IN operator.
• Here we can use the IN operator allows you to specify multiple values in a WHERE
clause.
• The IN operator is a shorthand for multiple OR conditions.
Step 1: Find cid for cname='Pune' or 'Chennai’.
The query will be,
SELECT cid
FROM City
WHERE cname='Pune' or 'Chennai'
Step 2: Using cid obtained in step 1 we can find the sid. The query will be
FROM Student_City
WHERE cid IN
(SELECT cid FROM City WHERE cname='Pune' or cname='Chennai')
• The inner query will return a set with members 101 and 103 and outer query
will return those sid for which cid is equal to any member of set (101 and 103 in
this case).
• So, it will return 1, 2 and 4.
Modification of Databases
• The modification of database is an operation for making changes in the existing
databases.
• Various operations of modification of database are insertion, deletion and
updation of databases.
1. Deletion: The delete command is used to delete the existing record.
Syntax
delete from table_name
where condition;
Example
delete from student
where RollNo=10
2. Insertion:
• The insert command is used to insert data into the table.
• There are two syntaxes of inserting data into SQL
Syntax
(i) Insert into table_name (column1, column2, column3, ...)
values (value1, value2, value3, ...);
(ii) insert into table_name
values (value1, value2, value3, ...);
Example
(i) insert into Student (RollNo,Name, Makrs) values (101, 'AAA',56.45)
(ii) insert into Student values(101,'AAA',56.45)
3. Update:
• The update statement is used to modify the existing records in the table.
update table_name
set column1-value1, column2=value2,...
where condition;
Example :
Delete student
Set Name='WWW'
where Roll No=101