Professional Documents
Culture Documents
DML Queries
DML Queries
DML Queries
1. Insert
2. Update
3. Delete
4. Select
INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.
INSERT INTO TABLE_NAME
(col1, col2, col3,.... col N) VALUES (value1, value2, value3, .... valueN);
For example:
INSERT INTO Student (Author, Subject) VALUES ("Ahmed", "DBMS");
UPDATE: This command is used to update or modify the value of a column in the table.
UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE CO
NDITION]
For example:
UPDATE students
SET User_Name = 'Ahmed'
WHERE Student_Id = '3'
DELETE FROM table_name [WHERE condition];
For example:
DELETE FROM Student
WHERE Author="Ahmed";
SELECT: This is the same as the projection operation of relational algebra. It is used to
select the attribute based on the condition described by WHERE clause.
SELECT expressions
FROM TABLES
WHERE conditions;
For example:
SELECT emp_name
FROM employee
WHERE age > 20;
Question No 2:
ii) Get names of Faculty members and the subject name that each faculty members
teaches?
iii) Display the marks of student having StdId”S001” in the subject having
SubId”Sub-01”?
iv) Display the names of Student enrolled in subject having SubId”Sub-07” in the
descending order of marks?
Select Stdid,Marks From ENROL ORDER BY Marks DESC;
Explain Keys. Primary key, Super Key, Foreign Key and their relations with the help of
examples.
Super Key – The set of attributes which can uniquely identify a tuple is known as Super
Key. So, a candidate key, primary key, and a unique key is a superkey, but vice-versa isn’t
true.
Primary Key – A set of attributes which are used to uniquely identify every tuple is also a
primary key. In the above example, since EmployeeID, InsuranceNumber and PanNumber
are candidate keys, any one of them can be chosen as a Primary Key. Here EmployeeID is
chosen as the primary key.
Foreign Key – An attribute that can only take the values present as the values of some
other attribute, is the foreign key to the attribute to which it refers. in the above example,
the Employee_ID from the Employee_Information Table is referred to the Employee_ID
from the Employee_Salary Table.