Query Processing System: BREB-2016)
Query Processing System: BREB-2016)
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
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
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"
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.
............. 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