0% found this document useful (0 votes)
74 views11 pages

Query Processing System: BREB-2016)

The document provides information about SQL (Structured Query Language) including its purpose, capabilities, clauses, operators, and functions. Some key points covered include: - SQL can be used to create and modify database structures and data as well as query database data. - Common SQL clauses include SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. - Logical operators like AND and OR are used in the WHERE clause to filter rows. Special operators like IN, BETWEEN, EXISTS can also be used for filtering. - Aggregate functions like COUNT, MAX, MIN, SUM return a single value rather than all rows and can be used in the SELECT list or HAVING clause
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views11 pages

Query Processing System: BREB-2016)

The document provides information about SQL (Structured Query Language) including its purpose, capabilities, clauses, operators, and functions. Some key points covered include: - SQL can be used to create and modify database structures and data as well as query database data. - Common SQL clauses include SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. - Logical operators like AND and OR are used in the WHERE clause to filter rows. Special operators like IN, BETWEEN, EXISTS can also be used for filtering. - Aggregate functions like COUNT, MAX, MIN, SUM return a single value rather than all rows and can be used in the SELECT list or HAVING clause
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Query Processing System

What is the full meaning of SQL? [BREB-2016]


a) Search and Query Language b) Simulation for Query Language
c) Standard Query Language d) Structured Query Language
Ans.:d
Which of the following is the original purpose of SQL?
a) To define the data structures
b) To specify the syntax and semantics of SQL data definition language
c) To specify the syntax and semantics of SQL manipulation language
d) All of the above.
Ans.: d
SQL can be used to:
a) create database structures only. b) query database data only.
c) modify database data only. d) All of the above can be done by SQL.
Ans.:d
The result of a SQL SELECT statement is a ________ . [Com( AME) 2019]
a) file b) report c) table d)form
Ans.:c
Which of the following do you need to consider when you make a table in SQL?
a) Data types b) Primary keys c) Default values d) All of the above.
Ans.: d
All of the following logical connectives are included in SQL except-- [Com bank SO(IT/ICT)-2019]
a)And b) or c) nor d) not
Ans.: c
Logical Operator: AND,OR,NOT
Special operators

Operator Description Operates on

The IN operator checks a value within a set of values separated Any set of values
IN by commas and retrieve the rows from the table which are of the same
matching.... datatype

The SQL BETWEEN operator tests an expression against a Numeric,


BETWEEN range. The range consists of a beginning, followed by an AND characters, or
keyword and an end expression.... datetime values

ANY compares a value to each value in a list or results from a A value to a list or
ANY query and evaluates to true if the result of an inner query a single - columns
contains at least one row.... set of values
ALL is used to select all records of a SELECT STATEMENT.
A value to a list or
It compares a value to every value in a list or results from a
ALL a single - columns
query. The ALL must be preceded by the comparison operators
set of values
and evaluates to TRUE if the query returns no rows....

SOME compare a value to each value in a list or results from a A value to a list or
SOME query and evaluate to true if the result of an inner query a single - columns
contains at least one row... set of values

The EXISTS checks the existence of a result of a subquery. The


EXISTS subquery tests whether a subquery fetches at least one
EXISTS Table
row. When no data is returned then this operator returns
'FALSE'...

A major challenge in mixing SQL with a general-purpose language is mismatching in


the ----[PKB-(Programmer)-2019]
a) Definition of data b) Manipulation of data
c) Execution of data d) Output of data
Ans.b
The SQL statement that queries or reads data from a table is – [ICB (AP)-2017]
a) SELECT b)READ c) QUERY d) None of the above
Ans. a
Which operator performs pattern matching?
a) BETWEEN operators b) LIKE operator
c) EXISTS operator d) None of these
Ans.:b
Explanation: LIKE is a keyword that is used in the WHERE clause. Basically, LIKE allows us to do a
search based operation on a pattern rather than specifying exactly what is desired (as in IN) or spell out a
range (as in BETWEEN).
The syntax is as follows:
SELECT "column_name" FROM "table_name"
WHERE "column_name" LIKE {PATTERN}
{PATTERN} often consists of wildcards. In SQL, there are two wildcards:
 1=% (percent sign) represents zero, one, or more characters.
 2=_ (underscore) represents exactly one character.

LIKE Operator Description


WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"

WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position

WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
Which SQL function is used to count the number of rows in a SQL query?
a) COUNT() b) NUMBER()
c) SUM() d) COUNT(*)
Ans.: d
Explanation: COUNT(*) takes null value row in to consideration.
The ISO standard defines five (5) aggregate functions namely;
AVG():- Average of the column
COUNT():- Number of records
MAX():- maximum of the column
MIN():- minimum of the column
SUM():- Sum of the column
Which of the following group functions ignore NULL values?
a) MAX b) COUNT c) SUM d) All of the above
Ans.:d
___________removes all rows from a table without logging the individual row deletions.
a) DELETE b) REMOVE c) DROP d) TRUNCATE
Ans.: d
Explanation: TRUNCATE statement is a Data Definition Language (DDL) operation that marks the
extents of a table for deallocation.
What operator tests column for the absence of data?
a) EXISTS operator b) NOT operator
c) IS NULL operator d) None of these
Ans.:c
Always use IS NULL to look for NULL values.
Syntax:
SELECT "column_name" FROM "table_name"
WHERE "column_name" IS NULL
Which of the following is a valid SQL type?
a) CHARACTER b) NUMERIC
c) FLOAT d) All of the above
Ans.:d
NULL is
a) the same as 0 for integer b) the same as blank for character
c) the same as 0 for integer and blank for character d) not a value
Ans.:d
In SQL, which command(s) is(are) used to change a table's storage characteristics?
a) ALTER TABLE b) MODIFY TABLE
c) CHANGE TABLE d) All of the above
Ans.:a
To change the structure of the table we use ALTER TABLE.
Sytax:
ALTER TABLE "table_name"
ADD "column_name" datatype
OR
ALTER TABLE "table_name"
DROP COLUMN "column_name"
In SQL, the-------command is used to recompile a view. [Com. Off(IT/ICT)-2019]
a) COMPILE VIEW b) DEFINE VIEW c) ALTER VIEW d) CREATE VIEW
Ans. c
Which of the SQL statements is correct?
a)SELECT Username AND Password FROM Users
b) SELECT Username, Password FROM Users
c) SELECT Username, Password WHERE Username = 'user1'
d) None of these
Ans.:b
Correct order of SELECT, FROM and WHERE clause is as follow:
SELECT column_name1, column_name2, .... FROM table_name
WHERE condition
Note : DISTINCT is use for remove repating data.
Summary
 The SQL WHERE clause is used to restrict the number of rows affected by a SELECT, UPDATE
or DELETE query.
 The WHERE clause can be used in conjunction with logical operators such as AND and OR,
comparison operators such as ,= etc.
 When used with the AND logical operator, all the criteria must be met.
 When used with the OR logical operator, any of the criteria must be met.
 The key word IN is used to select rows matching a list of values.
To remove the duplicate rows from the result of an SQL Select statement, the -------
qualifier specified include. [Com. (AME) -2019]
a)Only b) distinct c) Unique d) Single
Ans.: b
The SQL WHERE clause:
a) limits the row data are returned. b) limits the column data that are returned.
c) Both A and B are correct. d) Neither A nor B are correct.
Ans.:a
The HAVING clause does which of the following?
a) Acts EXACTLY like a WHERE clause.
b) Acts like a WHERE clause but is used for columns rather than groups.
c) Acts like a WHERE clause but is used for groups rather than rows.
d) Acts like a WHERE clause but is used for rows rather than columns.
Ans.: a
In SQL, aggregate functions can be used in the select list or the -------clause of a select
Statement or subquery. They cannot be used in a--------clause. [Com (AME) -2019]
a) Where, having b) Having, where
c) Group by. Having d) Group by. Where
Ans.: b
Syntex:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SQL:
SELECT COUNT(CustomerID), Country FROM Customers
GROUP BY Country HAVING COUNT(CustomerID) > 5;
Which SQL keyword is used to retrieve only unique values?
a) DISTINCTIVE b) UNIQUE
c) DISTINCT d) DIFFERENT
Ans.:c
A command that lets you change one or more fields in a record is
a) Insert b) Modify
c) Look-up d) All of the above
Ans.:b
Sometimes we need to change the data type of a column. To do this, we use the ALTER TABLE Modify
Column command.
Sytax:
ALTER TABLE table_name
MODIFY column_name "New Data Type"

SELECT SUBSTR('123456789', INSTR('abcabcabc', 'b'), 4) FROM DUAL;


a) 6789
b) 2345
c) 1234
d) 456789
Ans.:b

INSTR Function:- The INSTR function in SQL is used to find the starting location of a pattern in a
string. The syntax for the INSTR function is as follows:
INSTR (str, pattern): Find the starting location of pattern in string str.
SUBSTR Function:- The Substring function in SQL is used to grab a portion of the stored data. The
syntax for the SUBSTR function is as follows:
SUBSTR(str,pos,len): Starting with the position pos in string str select the characters upto the length len.
In the above query,
INSTR('abcabcabc', 'b') outputs 2 as the starting location of pattern and 4 is length so start from 2 and
total result = 2345 which is length 4
Which SQL keyword is used to sort the result-set?
a) SORT BY b) ORDER
c) ORDER BY d) SORT
Ans.:c
Table Employee has 10 records. It has a non-NULL SALARY column which is also UNIQUE. The
SQL statement SELECT COUNT(*) FROM Employee WHERE SALARY > ANY (SELECT
SALARY FROM EMPLOYEE); So result is..
a) 10 b) 9 c) 5 d) 0
Ans.:b
Note: ANY compares a value with each of the values in a list or results from a query and evaluates to true
if the result of an inner query contains at least one row. ANY must be preceded by comparison operators
(=, >, <, <=, >=, <>).
Employee table has 10 records and each value in non-NULL SALARY column is unique i.e different. So,
in those 10 records one of the records will be minimum which cannot be greater than any nine value of
the salary column. Hence the condition
WHERE SALARY > ANY (SELECT SALARY FROM employee) will be true nine times. So, the
COUNT(*) outputs =9.

The SQL statement: SELECT ROUND(45.926, -1) FROM DUAL;


a) is illegal b) prints garbage c) prints 045.926 d) prints 50
Ans.: d
Find all the cities whose humidity is 89
a) SELECT city WHERE humidity = 89;
b) SELECT city FROM weather WHERE humidity = 89;
c) SELECT humidity = 89 FROM weather;
d) SELECT city FROM weather;
Ans.:b
Find the temperature in increasing order of all cities
a) SELECT city FROM weather ORDER BY temperature;
b) SELECT city, temperature FROM weather;
c) SELECT city, temperature FROM weather ORDER BY temperature;
d) SELECT city, temperature FROM weather ORDER BY city;
Ans.:c
Find the names of these cities with temperature and condition whose condition is neither sunny nor
cloudy
a) SELECT city, temperature, condition FROM weather WHERE condition NOT IN ('sunny', 'cloudy');
b) SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN ('sunny',
'cloudy');
c) SELECT city, temperature, condition FROM weather WHERE condition IN ('sunny', 'cloudy');
d) SELECT city, temperature, condition FROM weather WHERE condition BETWEEN ('sunny',
'cloudy');
Ans.:a
Find all the tuples having temperature greater than 'Paris'.
a) SELECT * FROM weather WHERE temperature > (SELECT temperature FROM weather WHERE
city = 'Paris')
b) SELECT * FROM weather WHERE temperature > (SELECT * FROM weather WHERE city = 'Paris')
c) SELECT * FROM weather WHERE temperature > (SELECT city FROM weather WHERE city =
'Paris')
d) SELECT * FROM weather WHERE temperature > 'Paris' temperature
Ans.:a
Consider the following schemas :
Branch = (Branch-name, Assets, Branch-city)
Customer = (Customer-name, Bank_name, Customer-city)
Borrow = (Branch_name, loan_number, customer account_number)
Deposit = (Branch-name, Accountnumber,Customer_name, Balance)
Using relational Algebra, the Query that finds customers who have balance more than 10,000 is
a) πcustomer_name (σbalance >10000(Deposit))
b) σcustomer_name (σbalance >10000(Deposit))
c) πcustomer_name (σbalance >10000(Borrow))
d) σcustomer_name (πbalance >10000(Borrow))
Ans.: a
Using relational algebra, the query that finds Customers who have balance more than 10,000 is:
(i) From deposit
(ii) Apply condition balance > 10,000
(iii) Project customer name
Therefore,
πcustomer_name (σbalance >10000(Deposit))
The SELECT statement SELECT 'Hi' FROM DUAL WHERE NULL = NULL; Outputs
a) Hi b) FLASE c) TRUE d) Nothing
Ans.:d
Since Null is not a member of any data domain, it is not considered a "value", but rather a marker (or
placeholder) indicating the absence the value. Because of this, comparisons with Null can never result in
either True or False, but always in a third logical result, as Unknown. So, comparing NULL with NULL
results to NULL.
Let the statement
SELECT column1 FROM myTable;
return 10 rows. The statement
SELECT ALL column1 FROM myTable;
Will return
a) less than 10 rows b) more than 10 rows
c) exactly 10 rows d) None of these
Ans.: c
ALL are optional. Its presence or absence doesn't change the output. Unlike DISTINCT, it allows
duplicates in the output.
'AS' clause is used in SQL for
a) Selection operation. b) Rename operation.
c) Join operation. d) Projection operation.
Ans.:b

............. Joins two or more tables based on a specified column value not equaling a specified column
value in another table.
a) EQUIJOIN b) NON-EQUIJOIN
c) OUTER JOIN d) NATURAL JOIN
Ans.:b
Consider the following relation schema pertaining to a students database.
Student: (rollno, name, address)
Enroll: (rollno, courseno, coursename)
where the primary keys are shown underlined. The number of tuples in the Student and the
Enroll tables are 120 and 8 respectively. What are the maximum and the minimum number of
tuples that can be present in (Student Enroll), where denotes natural join?
a)8,8 b)120,8 c)960,8 d)960,120.
Ans.: d
The maximum number of tuples results when each of the 120 students enrolls for each of the
8 courses, giving 120 x 8 = 960 tuples. The minimum number of tuples results when all the
120 students enroll for the same course, giving 120 x 1 = 120 tuples.
Which of the following is an SQL trigger supported by Oracle? [ICB (AP)-2017]
a) BEFORE b)INSTEAD OF c) After d) All the above
Ans. d
Syntex:
create trigger [trigger_name]
[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]
Trigger is special type of ______procedure.
a) Stored b) Function
c) View d) Table
Ans.: a
Explanation: Triggers are used to assess/evaluate data before or after data modification using DDL and
DML statements.
How many types of triggers are present in SQL Server?
a) 4 b) 5
c) 8 d) 9
Ans.: a
Explanation: In Sql Server we can create four types of triggers Data Definition Language (DDL) triggers,
Data Manipulation Language (DML) triggers, CLR triggers and Logon triggers.
AFTER trigger in SQL Server can be applied to _____
a) Table b) Views
c) Table and Views d) Function
Ans.: c
Explanation: AFTER trigger fires after SQL Server completes the execution of the action successfully
that fired it.
Which of the following is not a typical trigger action?
a) Insert b) Select
c) Delete d) All of the mentioned
Ans.: b
Explanation: Valid trigger actions are INSERT, UPDATE and DELETE, or a combination of several,
separated by commas.
The CREATE TRIGGER statement is used to create the trigger. THE _____ clause specifies the
table name on which the trigger is to be attached. The ______ specifies that this is an AFTER
INSERT trigger.
a)for insert, on b) On, for insert
c)For, insert d) Both a and c
Ans.: b
Explanation: On, for insert
The triggers run after an insert, update or delete on a table. They are not supported for views.
Some Practices Question for M.C.Q:
 What is DBMS?
Database Management Systems (DBMS) are applications designed especially which enable user
interaction with other applications.
 What are the various kinds of interactions catered by DBMS?
The various kind of interactions catered by DBMS are:
 Data definition
 Update
 Retrieval
 Administration
 Who proposed the relational model?
Edgar F. Codd proposed the relational model in 1970.
 What do database languages do?
As special-purpose languages, they have:
 Data definition language
 Data manipulation language
 Query language
 Enlist the various relationships of database.
The various relationships of database are:
 One-to-one: Single table having drawn relationship with another table having similar kind of
columns.
 One-to-many: Two tables having primary and foreign key relation.
 Many-to-many: Junction table having many tables related to many tables.
 Define cursor.
A database object which helps in manipulating data row by row representing a result set is called cursor.
 Define sub-query.
A query contained by a query is called Sub-query.
 Define Aggregate functions.
Functions which operate against a collection of values and returning single value is called aggregate
functions . Like max(), min(), count() etc.
 Define Data Warehousing.
Storage and access of data from the central location in order to take some strategic decision is called Data
Warehousing. Enterprise management is used for managing the information whose framework is known
as Data Warehousing.
 Define Join and enlist its types.
Joins help in explaining the relation between different tables. They also enable you to select data with
relation to data in another table.
The various types are:
 INNER JOINs: Blank rows are left in the middle while more than equal to two tables are joined.
 OUTER JOINs: Divided into Left Outer Join and Right Outer Join. Blank rows are left at the
specified side by joining tables in other side.
Other joins are CROSS JOINs, NATURAL JOINs, EQUI JOIN and NON-EQUI JOIN.
 Database Architecture:
Database Architecture is logically of two types:
 2-tier DBMS architecture
 3-tier DBMS architecture

 What is the purpose of normalization in DBMS?


Normalization is the process of analyzing the relational schemas which are based on their respective
functional dependencies and the primary keys in order to fulfill certain properties.
The properties include:
 To minimize the redundancy of the data.
 To minimize the Insert, Delete and Update Anomalies.
What are the main differences between Primary key and Unique Key?
 The main difference between the Primary key and Unique key is that the Primary key can never
have a null value while the Unique key may consist of null value.
In each table, there can be only one primary key while there can be more than one unique key in a
table.
What is the use of DROP command and what are the differences between DROP,
TRUNCATE and DELETE commands?
 DROP command is a DDL command which is used to drop/delete the existing table, database,
index or view from the database.
 DROP and TRUNCATE commands are the DDL commands which are used to delete tables
from the database and once the table gets deleted, all the privileges and indexes that are related to
the table also get deleted. These 2 operations cannot be rolled back and so should be used only
when necessary.
 DELETE command, on the other hand, is a DML Command which is also used to delete rows
from the table and this can be rolled back.
 Note: It is recommended to use the ‘WHERE’ clause along with the DELETE command else the
complete table will get deleted from the database.
 Explain Entity, Entity Type, and Entity Set in DBMS?
 Entity is an object, place or thing which has its independent existence in the real world and about
which data can be stored in a database. For Example, any person, book, etc.
 Entity Type is a collection of entities that have the same attributes. For Example, the
STUDENT table contains rows in which each row is an entity holding the attributes like name,
age, and id of the students, hence STUDENT is an Entity Type which holds the entities having
the same attributes.
 Entity Set is a collection of entities of the same type. For Example, A collection of the
employees of a firm.
 What are the different levels of abstraction in the DBMS?
There are 3 levels of data abstraction in the DBMS.
 Physical Level: This is the lowest level of the data abstraction which states how the data is stored
in the database.
 Logical Level: This is the next level of the data abstraction which states the type of the data and
the relationship among the data that is stored in the database.
 View Level: This is the highest level in the data abstraction which shows/states only a part of the
database.
 What integrity rules exist in the DBMS?
There are 2 major integrity rules that exist in the DBMS.
 Entity Integrity: This states a very important rule that value of a Primary key can never have a
NULL value.
 Referential Integrity: This rule is related to the Foreign key which states that either the value of
a Foreign key is a NULL value or it should be the primary key of any other relation.
 What is a functional dependency in the DBMS?
 This is basically a constraint which is useful in describing the relationship among the different
attributes in a relation.
 Example: If there is some relation ‘R1’ which has 2 attributes as Y and Z then the functional
dependency among these 2 attributes can be shown as Y->Z which states that Z is functionally
dependent on Y.
What are different types of joins in SQL?
There are 4 types of SQL Joins:
 Inner Join: This type of join is used to fetch the data among the tables which are common in
both the tables.
 Left Join: This returns all the rows from the table which is on the left side of the join but only the
matching rows from the table which is on the right side of the join.
 Right Join: This returns all the rows from the table which is on the right side of the join but only
the matching rows from the table which is on the left side of the join.
 Full Join: This returns the rows from all the tables on which the join condition has put and the
rows which do not match hold null values.

You might also like