DML Queries

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Question No 1:

Write down the syntax and example of 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: It is used to remove one or more row from a table.

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:

Consider the following tables below:

STUDENT (StdId, StName, StAddress)


SUBJECT (SubId, SubName, FacId)
FACULTY (FacId, FacName, FacSpecialization)
ENROL (StdId, SubId, Marks)

Write the SQL statements for the following queries


i) Get name and Addresses of all students?

Select Stname ,Staddress From STUDENT

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”?

Select Marks from ENROL where Stdid==’S001’ AND 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;

v) Display all subjects whose name start with “Data”.

Select * From SUBJECT Where SubName LIKE Data%


Question No 3:

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.

You might also like