0% found this document useful (0 votes)
35 views8 pages

Day 2 PI Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

Subject Name: Database Management System

Day: 2

Topics Covered: Set Operations (Union, Union all, Intersection, Cartesian product and set difference) and their
differences, Select command using different clauses and predicates like having, order by, group by, LIKE predicate,
In clause, between clause, AND, OR and NOT operations and Use of Flashback and timestamp command.SQL-What
is SQL?Aggregate functions,

GRANT and REVOKE

Commit, Rollback and Checkpoints can be added.

Creating User

Creating Roles

Then Grant and Revoke of Privileges both DDL and DML

Question 1: How do we implement CHECK Constraint using Boolean operators?

Answer: CHECK constraints are rules used to limit values that are accepted by one or more columns.

For example, Products with unit price between INR 5000 to INR 100000 are allowed only. This prevents product unit
price from being entered beyond the regular price range.

 The logical expression would be the following: UnitPrice>= 5000 AND UnitPrice<= 100000

Question 2: Why do we need to have columns that are not part of GROUP BY Clause as part of aggregate function

Answer:- This is also the same reason as above. If we have some columns in the SELECT list that are not part of the
GROUP BY clause, then it will change the requirement of the query itself. Still if we need to include them in
SELECT list but not in  GROUP BY clause, then we have use some aggregate function on them so that their value
remains same but it will be displayed in the SELECT lis

Question 3: Why do we need to use Transaction Control Language?

Answer:-  To safeguard enterprise data (to make enterprise data consistent and to achieve data integrity).A
transaction is the propagation of one or more changes to the database. For example, if we are creating a record or
updating a record or deleting a record from the table, then we are performing a transaction on the table. It is important
to control transactions to ensure data integrity and to handle database errors.

Question 4: What is the rule of Transaction?

Answer:- The rule of transaction tells that either all the statements in the transaction should be executed successfully
or none of those statements to be executed.

Department of Computer Science and EngineeringPage 1


Question 5: How to implement/ control transactions in SQL Server?

Answer:- The following commands are provided by TCL to control transactions:

  BEGIN TRANSACTION:  To start the transaction

  COMMIT: to save the changes.

  ROLLBACK TRANSACTION: to roll back the changes.

  SAVE TRANSACTION: creates points within groups of transactions in which to ROLLBACK

Question 6: How would we use DISTINCT Statement? What is its use?

Answer: The particular statement is used with the SELECT statement. In the event that the tables contain duplicate
values then DISTINCT is used to choose diverse values among duplicate tables.

E.g.SELECT DISTINCT Country FROM Customers;

Question 7:What is the need for group functions in SQL?

Answer:Group functions work on the set of rows and return one result per group. Some of the commonly used group
functions are: AVG, COUNT, MAX, MIN, SUM, VARIANCE.

Question 8. Can you nest aggregate functions?

Answer: Yes, you can have nested aggregate functions up to two levels deep. For example, you can use
MAX(COUNT(*)).

Question 9. Does COUNT return the number of columns in a table?

Answer: No, it returns the number of records in a table.

Question 10. What’s the difference between COUNT(column) and COUNT(DISTINCT column)?

Answer: COUNT(column) will return the number of non-NULL values in that column. COUNT(DISTINCT
column) will return the number of unique non-NULL values in that column.

Question 11: What’s wrong with this query?

 SELECT department_id, count(*)

Department of Computer Science and EngineeringPage 2


FROM department;

Answer: There is no GROUP BY clause and it will display an error. Because we have used the COUNT function,
which is an aggregate function, along with a database field, we need to add a GROUP BY clause. It should GROUP
BY the department_id column.

Question 12: What’s wrong with this query?

 SELECT department_id, count(*)

FROM department

WHERE count(*) > 5

GROUP BY department_id;

Answer: The WHERE clause cannot include any checks on the aggregate column – even if a GROUP BY has been
performed.This is because the WHERE happens before the grouping, so there is no way for the WHERE clause to
know what the value of the COUNT function is.To resolve this, use the HAVING clause to check for COUNT(*) > 5.

Question 13. Write a query to retrieve duplicate records from a table.

Answer:- SELECT EmpID, EmpFname, Department COUNT(*) 

FROM EmployeeInfo GROUP BY EmpID, EmpFname, Department 

HAVING COUNT(*) > 1;

Question 14. What are the different DDL commands in SQL? Give a description of their purpose.

Answer:- . CREATE: creates objects in the database

ALTER: makes changes to objects in the database

DROP: removes objects from the database

TRUNCATE: deletes all data from a table

COMMENT: adds comments to the data dictionary

RENAME: renames an object in the database

Question 15: What are the different subsets of SQL?

Answer:- Data Definition Language (DDL) – It allows you to perform various operations on the database such as
CREATE, ALTER, and DELETE objects.

Data Manipulation Language(DML) – It allows you to access and manipulate data. It helps you to insert, update,
delete and retrieve data from the database.
Department of Computer Science and EngineeringPage 3
Data Control Language(DCL) – It allows you to control access to the database. Example – Grant, Revoke access
permissions.

Question 16: Difference between commit and roll back commands?

Answer: COMMIT statement makes all the updations made by all commands to be stored permanently whereas
ROLLBACK erases all the updations made by commands.

Question 17: What is the use of checkpoints in DBMS?

Answer: Check point is a mechanism that aids in database recovery. Checkpoint declares a point before which the
DBMS was in consistent state and all the transactions have been committed.

Question 18: What is RDBMS? How is it different from DBMS?

Answer: A relational database management system (RDBMS) is a set of applications and features that allow IT
professionals and others to develop, edit, administer, and interact with relational databases. Most commercial
relational database management systems use Structured Query Language (SQL) to access the database, which is
stored in the form of tables.
The RDBMS is the most widely used database system in businesses all over the world. It offers a stable means of
storing and retrieving massive amounts of data..

Question 19. What are aggregate and scalar functions?

Answer: Aggregate functions are used to evaluate mathematical calculation and return single values. This can be
calculated from the columns in a table. Scalar functions return a single value based on the input value.

Example -.

Aggregate – max(), count - Calculated with respect to numeric.

Scalar – UCASE(), NOW() – Calculated with respect to strings.

Question 20: How to select unique records from a table?

Answer: Select unique records from a table by using DISTINCT keyword.

Select DISTINCT StudentID, StudentName from Student.

Question 21: Does SQL support programming?

 Answer: SQL refers to the Standard Query Language, which is not actually the programming language. SQL doesn't
have a loop, Conditional statement, logical operations, it can not be used for anything other than data manipulation. It
is used like commanding (Query) language to access databases. The primary purpose of SQL is to retrieve,
manipulate, update and perform complex operations like joins on the data present in the database.

Question 22: What is Data Control Language?

Department of Computer Science and EngineeringPage 4


Answer: Data control language allows you to control access to the database. DCL is the only subset of the database
which decides that what part of the database should be accessed by which user at what point of time. It includes two
commands GRANT and REVOKE.

Question 23: Differentiate between grant and revoke

Answer: GRANT: to grant the specific user to perform a particular task

REVOKE: to cancel previously denied or granted permissions.

Question 24: What are UNION, MINUS and INTERSECT commands?

Answer: The UNION operator combines and returns the result-set retrieved by two or more SELECT statements.

The MINUS operator in SQL is used to remove duplicates from the result-set obtained by the second SELECT query
from the result-set obtained by the first SELECT query and then return the filtered results from the first.

The INTERSECT clause in SQL combines the result-set fetched by the two SELECT statements where records from
one match the other and then returns this intersection of result-sets

Question 25: What is the SQL Grant statement

 Answer: In SQL, the GRANT statement is used to give (or “grant”) one or more privileges/permissions to a
particular database user. Here’s what the syntax for the GRANT statement looks like:

Syntax for the GRANT statement

GRANT privilege [, privilege ... ] /* can add more privileges here too */

[ON database object ] /*object can be tables, views, etc.. */

TO grantee [, grantee ...] /*user, PUBLIC, or role*/

[WITH GRANT OPTION | WITH ADMIN OPTION];

Question 26: What do you understand by SQL Grantee list

Answer: It should be clear from the syntax of the GRANT statement shown above that you can specify more than
one database user or role that should receive the privilege(s) being granted.

Question 27: What is the SQL REVOKE statement

Answer: In SQL, the REVOKE statement is used to take back/remove (or “revoke”) one or more
privileges/permissions from a particular database user. Here’s what the syntax for the REVOKE statement looks like:

Syntax for the REVOKE statement

Department of Computer Science and EngineeringPage 5


Question 28: What do you understand by SQL revoke Grantee list?

Answer: It should be clear from the syntax of the REVOKE statement shown above that you can specify more than
one database user or role that should receive the privilege(s) being revoked. In this context, GRANTEE’s refer to the
users from whom the privileges are being revoked.

Question 29: Define COMMIT

Answer: When a COMMIT is used in a transaction all changes made in the transaction are written into the database
permanently.

BEGIN TRANSACTION;   

DELETE FROM HumanResources.JobCandidate  

WHERE JobCandidateID = 13;   

COMMIT TRANSACTION; 

Question 30: What is a SYSTEM Privilege?

Answer: Rights are given to a user, usually by the DBA, to perform a particular action on the database schema
objects like creating tablespaces.

The following are examples of system privileges that can be granted to users:

CREATE TABLE allows a grantee to create tables in the grantee's schema.

CREATE USER allows a grantee to create users in the database.

CREATE SESSION allows a grantee to connect to an Oracle database to create a user session.

Question 31: What are Object Privileges?

Answer: An object-level privilege is a permission granted to a database user account or role to perform some action
on a database object. These object privileges include SELECT, INSERT, UPDATE, DELETE, ALTER, INDEX on
tables, and so on.

The following examples are object privileges that can be granted to users:

SELECT ON hr.employees TO myuser

INSERT ON hr.employees TO myuser

Question 32: What is the role of GRANT and REVOKE commands with example?

Answer: The GRANT command enables privileges on the database objects and the REVOKE command removes
them. They are DCL commands:-

Department of Computer Science and EngineeringPage 6


GRANT CREATE ANY TABLE TO username

GRANT sysdba TO username

GRANT DROP ANY TABLE TO username

REVOKE CREATE TABLE FROM username

Question 33: What are transactions and their controls?

Answer: A  transaction can be defined as the sequence task that is performed on databases in a logical manner to
gain certain results. Operations like Creating, updating, deleting records performed in the database come from
transactions.

In simple words, we can say that a transaction means a group of SQL queries executed on database records.

There are 4 transaction controls such as

COMMIT: It is used to save all changes made through the transaction.

ROLLBACK: It is used to roll back the transaction. All changes made by the transaction are reverted back and the
database remains as before.

SET TRANSACTION: Set the name of the transaction.

SAVEPOINT: It is used to set the point where the transaction is to be rolled back.

Question 34: Explain the working of SQL Privileges?

Answer: SQL GRANT and REVOKE commands are used to implement privileges in SQL multiple user
environments. The administrator of the database can grant or revoke privileges to or from users of database objects
by using commands like SELECT, INSERT, UPDATE, DELETE, ALL, etc.

GRANT Command: This command is used to provide database access to users other than the administrator.

Syntax:

GRANT privilege_name

 ON object_name

GRANT privilege_name

 ON object_name

 TO {user_name|PUBLIC|
role_name}

Department of Computer Science and EngineeringPage 7


 [WITH GRANT OPTION];

In the above syntax, the GRANT option indicates that the user can grant access to another user too.

REVOKE command: This command is used to provide database deny or remove access to database objects.

Syntax:

REVOKE privilege_name

 ON object_name

 FROM {user_name|PUBLIC|
role_name};

Department of Computer Science and EngineeringPage 8

You might also like