0% found this document useful (0 votes)
4 views10 pages

Final Viva

The document covers various SQL commands including DDL, DML, DQL, DCL, and TCL, along with explanations of their functionalities and examples. It also addresses concepts such as primary keys, foreign keys, constraints, views, normalization, triggers, and transaction properties like atomicity, consistency, isolation, and durability. Additionally, it includes viva questions and answers related to these topics, providing a comprehensive overview of SQL and database management principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Final Viva

The document covers various SQL commands including DDL, DML, DQL, DCL, and TCL, along with explanations of their functionalities and examples. It also addresses concepts such as primary keys, foreign keys, constraints, views, normalization, triggers, and transaction properties like atomicity, consistency, isolation, and durability. Additionally, it includes viva questions and answers related to these topics, providing a comprehensive overview of SQL and database management principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

IMPLEMENTATION OF BASIC DDL COMMANDS

Viva Questions:

1.What happens if you omit the WHERE clause in the UPDATE statement?

All the rows in the table are modified.


2. What is the difference between VARCHAR2 AND CHAR datatypes?

VARCHAR2 represents variable length character data, whereas CHAR represents


fixed length character data.

3.Write SQL Query to display the current date.


SQL has built-in function called GetDate() which returns the current timestamp. This
will work in Microsoft SQL Server, other vendors like Oracle and MySQL
also has equivalent functions.
Ans: Select GetDate();

4.Can we rename a column in the output of SQL query?


Yes using the following syntax we can do this.

SELECT column_name AS new_name FROM table_name;

5.Suppose a Student column has two columns, Name and Marks. How to get
name and marks of top three students.

SELECT Name, Marks FROM Student s1 where 3 <= (SELECT COUNT(*) FROM
Students s2 WHERE s1.marks = s2.marks)

6.Difference between TRUNCATE, DELETE and DROP commands?


DELETE removes some or all rows from a table based on the condition. It can be
rolled back.

IMPLEMENTATION OF DML BASIC COMMANDS


Viva Questions:

1.List the constraints used in DDL

NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
2.Create a table and insert the values in table?

Create Table:
SQl>createtableship(shipidNUMBER,shipnameVARCHAR2(10),originVARCHAR2(1
5),destination VARCHAR2(15),passenger NUMBER);
Insert querry:
SQL> INSERT INTO ship VALUES(101, 'titanic', 'america', 'canada', 528);
1 row created.
SQL> INSERT INTO ship VALUES(102, 'alligator', 'america', 'africa', 524);
1 row created.
SQL> INSERT INTO ship VALUES(103, 'cairo', 'german', 'india', 628);
1 row created.

3.What is the syntax to add record to a table?


To add record in a table INSERT syntax is used.

Ex: INSERT into table_name VALUES (value1, value2..);

4.Define SQL Delete statement.


Ans. Delete is used to delete a row or rows from a table based on the specified
condition.

Basic syntax is as follows:

Syntax: DELETE FROM table_name WHERE <Condition>;

IMPLEMENTATION OF DML BASIC COMMANDS


Viva Questions:

1.List the constraints used in DDL

 NOT NULL
 UNIQUE
 PRIMARY KEY
 FOREIGN KEY
 CHECK
 DEFAULT

2.Create a table and insert the values in table?

Create Table:
SQl>createtableship(shipidNUMBER,shipnameVARCHAR2(10),orignVARCHAR2(15
),
destination VARCHAR2(15),passenger NUMBER);
Insert querry:
SQL> INSERT INTO ship VALUES(101, 'Titanic', 'America', 'Canada', 528);
1 row created.

SQL> INSERT INTO ship VALUES(102, 'Alligator', 'America', 'Africa', 524);


1 row created.

SQL> INSERT INTO ship VALUES(103, 'Cairo', 'German', 'India', 628);


1 row created.
3.What is the syntax to add record to a table?
To add record in a table INSERT syntax is used.

Ex: INSERT into table_name VALUES (value1, value2..);

4.Define SQL Delete statement.


Ans. Delete is used to delete a row or rows from a table based on the specified
condition.
Basic syntax is as follows:
Syntax: DELETE FROM table_name WHERE <Condition>;

IMPLEMENTATION OF DQL COMMANDS


Viva Questions:

1. What is a primary key?


Ans. A Primary key is column whose values uniquely identify every row in a table.
Primary key values can never be reused.

2. What are foreign keys?


When a one table’s primary key field is added to related tables in order to create the
common field which relates the two tables, it called a foreign key in other tables.
Foreign Key constraints enforce referential integrity
3. What is CHECK Constraint?
A CHECK constraint is used to limit the values or type of data that can be stored in a
column. They are used to enforce domain integrity.

4. Is it possible for a table to have more than one foreign key?


Ans. Yes, a table can have many foreign keys and only one primary key.

5. What are the possible values for BOOLEAN data field.


Ans. For a BOOLEAN data field two values are possible: -1(true) and 0(false).
6. Write a SQL SELECT query that only returns each name only once from a
table?
Ans. To get the each name only once, we need to use the DISTINCT keyword.
SELECT DISTINCT name FROM table_name;

IMPLEMENTATION OF DQL COMMANDS (with constraint)


Viva Questions:

1. display the student id, student name and department of the student whose
the semester in between 5 and 6

ANS: SELECT studid,sname,department FROM student WHERE sem


BETWEEN 5 AND 6;

STUDID SNAME DEPAR


---------------------------------------------------------
101 DEEPI IT
104 REVA IT
106 ANANT CSE
108 SASI IT

2. How we can avoid duplicating records in a query?


Ans. By using DISTINCT keyword duplicating records in a query can be
avoided.

3. Explain the difference between Rename and Alias?


Ans. Rename is a permanent name given to a table or column whereas Alias
is a temporary name given to a table or column.

4. Write an SQL Query to print the name of the distinct employee whose
DOB is between 01/01/1960 to 31/12/1975.

Answer: This SQL query is tricky, but you can use BETWEEN clause to get
all records whose date fall between two dates.

ANS:SELECT EmpName FROM Employees WHERE Salary>=10000;

IMPLEMENTATIN OF DCL COMMANDS


Viva Questions:

1. List the DCL commands?


The DCL commands are:
 Grant
 Revoke

2. Write the syntax for grant


Syntax:
Grant <privileges> on <table_name> to user;
3. Write the syntax for grant
Syntax:
Revoke <privileges> on <table_name> from user;

IMPLEMENTATION OF TCL COMMANDS


Viva Questions:

1. List the TCL commands


 Commit
 Save point
 Rollback

2. Define COMMIT ?
Ans. COMMIT saves all changes made by DML statements.

3. What is a transaction?
Ans. A transaction is a sequence of code that runs against a database. It
takes database from one consistent state to another.

4. What is difference between UNIQUE and PRIMARY KEY constraints?


Ans. A table can have only one PRIMARY KEY whereas there can be any
number of UNIQUE keys.Primary key cannot contain Null values whereas
Unique key can contain Null values.

5. What is a composite primary key?


Ans. Primary key created on more than one column is called composite
primary key.
6. What is the use of save point?
Answer :
A SAVEPOINT is a point in a transaction when you can roll the transaction
back to a certain point without rolling back the entire
transaction.
Syntax: save point save point name;
AGGREGATE FUNCTIONS
Viva Questions:

1. List thesome of the Aggregate function


 MAX
 MIN
 COUNT
 SUM
 AVG

2.To display the department, sem and student name from the table student
based on department in descending order.
Ans: SELECT department, sem, sname FROM student ORDER BY department DESC,
sem DESC, sname DESC;
DEPAR SEM SNAME
-------------------------------------------------
IT 5 DEEPI
IT 5 SASI
IT 5 REVA
CSE 7 SHAN
CSE 5 ANANT

3.Count the total number of students in the table

Ans: SELECT COUNT (eid) AS STUDENTS_REGISTERED FROM exam;

4.SQL Query to find Max Salary from each department.


Answer: You can find the maximum salary for each department by
grouping all records by DeptId and then using MAX() function to calculate
maximum salary in each group or each department.
Ans: SELECT DdepteptID, MAX(Salary) FROM Employee GROUP
BY DeptID.

SET OPERATIONS

1. Define UNION, MINUS, UNION ALL, INTERSECT ?


MINUS – returns all distinct rows selected by the first query but not by the second.
UNION – returns all distinct rows selected by either query
UNION ALL – returns all rows selected by either query, including all duplicates.
INTERSECT – returns all distinct rows selected by both queries.
1. What is Referential Integrity?
Ans. Set of rules that restrict the values of one or more columns of the tables
based on the values of primary key or unique key of the referenced table.

2. What do you mean by query optimization?


Ans. Query optimization is a process in which database system compares
different query strategies and selects the query with the least cost.
3. Define a temp table?
Ans. A temp table is a temporary storage structure to store the data
temporarily.
4. What is schema?
Ans. A schema is collection of database objects of a User.
5. What is Table?
Ans. A table is the basic unit of data storage in the database management
system. Table data is stored in rows and columns.
6. What is difference between Local and Global temporary table?
Ans. If defined in inside a compound statement a local temporary table exists
only for the duration of that statement but a global temporary table exists
permanently in the db but its rows disappears when the connection is closed.
7. What is a checkpoint and when does it occur?

8. A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the


DBMS can reduce the amount of work to be done during restart in the event
of subsequent crashes.

9. What are the unary operations in Relational Algebra?


a. PROJECTION and SELECTION.

10. What are set operators in SQL?

Union, intersect or minus operators are called set operators.

Viva Questions:

1. Define join and name different type of joins?


Ans. Join keyword is used to fetch data from related two or more tables. It returns
rows where there is at least one match in both the tables included in join.
Type of joins are-
o Right Join
o Outer Join
o Full Join
o Cross Join
o Self Join.
 Consider the table Employee and payment :
join on these two table

 SELECT emp_id, name, age,salary FROM Employee e, Payment p


WHERE e.Emp_id =p.Payment_id;

Nested sub query:


Viva Questions:

1. SQL Query to find Max Salary from each department.


Ans ; SELECT DeptID, MAX(Salary) FROM Employee GROUP BY DeptID.

2. Write the querry using not in staemnet


Ans:SELECT studentID, sname FROM cseitstudent WHERE studentID NOT
IN
(SELECT studentID FROM placement);
STUDENTID SNAME
------------------------------------------------
101 Ranvir

3. What is the Sub query?


Ans. A Sub query is sub set of select statements whose return values are used in
filtering conditions of the main query
.

4. What is Referential Integrity?


Ans. Set of rules that restrict the values of one or more columns of the tables
based on the values of primary key or unique key of the referenced table.

Viva Questions:

1. What is a View?
Ans. A view is a virtual table which contains data from one or more tables. Views
restrict data access of table by selecting only required values and make complex
queries easy.

2. What are the advantages of Views?


Ans. Advantages of Views:
Views restrict access to the data because the view can display selective
columns from the table.
Views can be used to make simple queries to retrieve the results of
complicated queries.

3. Define Normalization Ans. The process of table design to minimize the data
redundancy is called normalization. We need to divide a database into two or more
table and define relationships between them.
TRIGGER
Viva Questions:

1. What is Trigger?
Ans. Trigger allows us to execute a batch of SQL code when a table event
occurs (Insert, update or delete command executed against a specific table)

2. 25. Write an SQL Query to find name of employee whose name Start with
‘M’
Answer :
a.
SELECT * FROM Employees WHERE EmpName like 'M%';.

3. What is a Unique Key?

Unique key is same as primary with the difference being the existence of null.
Unique key field allows one value as NULL value.
4. What is Atomicity?
Answer :
Atomicity of a transaction is nothing but in a transaction either all operations
can be done or all operation can be undone, but some operations are done
and some operation are undone should not occur.
5. What is Consistency?
Answer :
Consistency means, after a transaction completed with successful, the data
in the data store should be a reliable data this reliable data is also called as
consistent data.
6. What is Isolation?
Answer :
Isolation means, if two transactions are going on same data then one
transaction will not disturb another transaction.
7. What is Durability?
Answer :
Durability means, after a transaction is completed the data in the
data store will be permanent until another transaction is going to be
performed on that data.

You might also like