Anda di halaman 1dari 17

SQL Interview Question and Answers

1. Define SQL?
Structured query language is the standard command set
used to communicate with the relational database management
system.
2. Define Dbms?
A Database Management system consists of a collection of
interrelated data and set of programs to access that data.
3. What is the purpose of Database systems?
A Database Management system provides a secure and
survivable medium for the storage and retrieval of data.In the
real world, the data is shared among several users and is
persistent.
4. State the different between Security and Integrity?
Security is a protection from malicious attempts to steal or
modify data.

Integrity constraints guard against accidental damage to the
database, by ensuribg that authorized changes to the database
do not result in a loss of data consistency.
5. Define Normalisation?
Normalisation is an essential part of database design. A good
understanding of the semantic of data helps the designer to
built efficient design using the concept of normalization.
6. What are the purpose of Normalisation?
Minimize redundancy in data.
Remove insert, delete and update anamoly during the database
activities.
Reduce the need to reorganize data it is modified or enhanced.
7. Define Primary Key?
The primary key is the columns used to uniquely identify each row of a table.
A table can have only one primary key.
No primary key value can appear in more than one row in the table.
8. Define Unique Key?
Unique key is a one or more column that must be unique for each row of the table.
It is similar to primary key. Primary key column will not accept a null. Whereas the
unique key column will accept a null values.

9. Define Foreign Key?
A foreign Key is a combination of columns with value is based on the primary key
values from another table. A foreign key constraint also known as Referential
Integrity Constraint.
10. Define View?
A View is a database object that is a logical representation of a table.
It is derived from a table but has no longer of its own and often may be used in the
same manner as a table.
A view is a virtual table that has columns similar to a table.
A view does not represent any physical data.
11. Compare and contrast TRUNCATE and DELETE for a table?
Both the truncate and delete command have the desired outcome of getting rid of all
the rows in a table. The difference between the two is that the truncate command is
a DDL operation and just moves the high water mark and produces a now rollback.
The delete command, on the other hand, is a DML operation, which will produce a
rollback and thus take longer to complete.
12. What is cursors?
Cursor is a database object used by applications to manipulate data in a set on a
row-by-row basis, instead of the typical SQL commands that operate on all the rows
in the set at one time.
13. Define SubQuery?
Nesting of Queries one within the other is called as a Subquery.
A table can have only one primary key.
14. What are the different types of subquery?
Single row subquery
Multiple row subquery
Correlated row subquery

15. What are the different types of replication?
The SQL Server 2000-supported replication types are as follows
Transactional
Snapshot
Merge
16. What is User Defined Functions?
User-Defined Functions allow to define its own T-SQL functions that can accept 0 or
more parameters and return a single scalar data value or a table data type.
17. Define Self Join?
Self join means joining one table with itself.
The self join can be viewed as a join of two copies of the same table.
18. Define Sequence?
A Sequence is a database object that can be used to provide very quick generation
of unique numbers.
19. Define Joins?
A Join combines columns and data from two or more tables (and in rare cases, of
one table with itself).
20. What are the types of Joins?
Equi joins
Cartesian Joins
Outer Joins
Self Joins.

21. Define Equi Joins?
A Equi Join is a join in which the join comparison operator is an equality. When two
tables are joined together using equality or values in one or more columns, they
make an Equi Join.
22. Define Cartesian Join?
Joining two tables without a whereclause produces a Cartesian join which combines
every row in one table with every row in another table.
23. What are three SQL keywords used to change or set someone's
permissions?
GRANT, DENY, and REVOKE
24. What are primary keys and foreign keys?
Primary keys are the unique identifiers for each row. They must contain unique
values and cannot be null. Due to their importance in relational databases, Primary
keys are the most fundamental of all keys and constraints. A table can have only
one Primary key.

Foreign keys are both a method of ensuring data integrity and a manifestation of
the relationship between tables.
25. Define data model?
Underlying the structure of the database is called as data model.
26. What is an Entity?
It is a 'thing' in the real world with an independent existence.

27. What is BCP? When does it used?
BulkCopy is a tool used to copy huge amount of data from tables and views. BCP
does not copy the structures same as source to destination.
28. Explain the use of the by GROUP BY and the HAVING clause?
The GROUP BY partitions the selected rows on the distinct values of the column on
which the group by has been done.
The HAVING selects groups which match the criteria specified.
29. What is DataWarehousing?
According to Bill Inmon, known as father of Data warehousing. A Data warehouse is
a subject oriented, integrated ,time variant, non volatile collection of data in support
of managements decision making process.
30. What are the advantages of Database?
Redundancy can be reduced
Inconsistence can be avoided
The data can be shared
Standards can be enforced
Security can be enforced
Integrity can be maintained
31. What are the advantage of SQL?
The advantages of SQL are
SQL is a high level language that provides a greater degree of abstraction than
procedural languages.
SQL enables the end users and system personnel to deal with a number of Database
management systems where it is available.
Application written in SQL can be easily ported across systems.
32. What is the difference between join and outer join?
Outer joins return all rows from at least one of the tables or views mentioned in
the FROM clause, as long as those rows meet any WHERE or HAVING search
conditions.

A join combines columns and data from two are more tables.

33. Define Boyce coded normal form?
A relation is said to be in Boyce coded normal form if it is already in the third normal
form and every determine is a candidate key.
34. What are the transaction properties?
Atomicity
Consistency
Isolation
Durability
35. What is data mining?
Data mining refers to using variety of techniques to identify nuggests of information
or decision making knowledge in bodies of data and extracting these in such a way
that they can be put in the use in the areas such as decision support, predication,
forecasting and estimation.
36. Compare DBMS versus object oriented DBMS?
DBMS consists of a collection of interrelated data and a set of programs to access
that data.
The object oriented DBMS is one of the type of dbms in which information is stored
in the form of objects.
37. What are the types of SQL Commands?
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Query Language (DQL)
Data Control Language (DCL)
38. What is an attribute?
An entity is represented by a set of attributes.
Attributes are descriptive properties possessed by each member of an entity set.
There are different types of attributes.
Simple
Composite
Single-valued
Derived
39. What are the different types of data models ?
Entity relationship model
Relational model
Hierarchical model
Network model
Object oriented model
Object relational model
40. What is an active database?
Active database is a database that includes active rules, mostly in the form of ECA
rules(Event Condition rules).
Active database systems enhance traditional database functionality with powerful
rule processing cabalities, providing a uniform and efficient mechanism for database
system applications.
41. What are ACID properties?


Atomicity
Consistency
Isolation
Durability
42. Define Self Join?
Self join means joining one table with itself.
The self join can be viewed as a join of two copies of the same table.
43. What is a tuple?
A tuple is an instance of data within a relational database.
44. What is meant by embedded SQL?
They are SQL statements that are embedded with in application program and are
prepared during the program preparation process before the program is executed.
After it is prepared, the statement itself does not change(although values of host
variables specified within the statement might change).

45. What is Functional Dependency?
A Functional dependency is denoted by X Y between two sets of attributes X and Y
that are subsets of R specifies a constraint on the possible tuple that can form a
relation state r of R. The constraint is for any two tuples t1 and t2 in r if t1[X] =
t2[X] then they have t1[Y] = t2[Y]. This means the value of X component of a tuple
uniquely determines the value of component Y.
46. What are the different phases of transaction?
The different phases of transaction are
Analysis phase
Redo Phase
Undo phase
47. What the difference between UNION and UNIONALL?
Union will remove the duplicate rows from the result set while Union all doesnt.
48. What is diffrence between Co-related sub query and nested sub query?
Correlated subquery runs once for each row selected by the outer query. It
contains a reference to a value from the row selected by the outer query.

Nested subquery runs only once for the entire nesting (outer) query. It does not
contain any reference to the outer query row.
49. What is the use of DBCC commands?
DBCC stands for database consistency checker. We use these commands to check
the consistency of the databases, i.e., maintenance, validation task and status
checks.
50. What is a Linked Server?
Linked Servers is a concept in SQL Server by which we can add other SQL Server to
a Group and query both the SQL Server dbs using T-SQL Statements. With a linked
server, you can create very clean, easy to follow, SQL statements that allow remote
data to be retrieved, joined and combined with local data.

51. What is Collation?
Collation refers to a set of rules that determine how data is sorted and compared.
Character data is sorted using rules that define the correct character sequence, with
options for specifying case-sensitivity, accent marks, kana character types and
character width.
52. What are different type of Collation Sensitivity?
The different phases of transaction are
Case sensitivity
Accent sensitivity
Kana Sensitivity
Width sensitivity
53. What is the difference between a primary key and a unique key?
Both primary key and unique enforce uniqueness of the column on which they are
defined. But by default primary key creates a clustered index on the column, where
are unique creates a nonclustered index by default. Another major difference is that,
primary key doesnt allow NULLs, but unique key allows one NULL only.
54. What is the difference between Function and Stored Procedure?
UDF can be used in the SQL statements anywhere in the WHERE / HAVING / SELECT
section where as Stored procedures cannot be.
UDFs that return tables can be treated as another rowset. This can be used in JOINs
with other tables.
Inline UDFs can be though of as views that take parameters and can be used in
JOINs and other Rowset operations.
55. What command do we use to rename a db?
sp_renamedb oldname , newname
If someone is using db it will not accept sp_renmaedb. In that case first bring db to
single user using sp_dboptions. Use sp_renamedb to rename database. Use
sp_dboptions to bring database to multi user mode.
56. What is BCP?
BulkCopy is a tool used to copy huge amount of data from tables and views. BCP
does not copy the structures same as source to destination.

57. What is Cross Join?
A cross join that does not have a WHERE clause produces the Cartesian product of
the tables involved in the join. The size of a Cartesian product result set is the
number of rows in the first table multiplied by the number of rows in the second
table.
58. What is Storage Manager?
It is a program module that provides the interface between the low-level data stored
in database, application programs and queries submitted to the system.
59. What are stored-procedures? And what are the advantages of using them?
Stored procedures are database objects that perform a user defined operation. A
stored procedure can have a set of compound SQL statements. A stored procedure
executes the SQL commands and returns the result to the client. Stored procedures
are used to reduce network traffic.
60. What is database Trigger?
A database trigger is a PL/SQL block that can defined to automatically execute for
insert, update, and delete statements against a table. The trigger can e defined to
execute once for the entire statement or once for every row that is inserted,
updated, or deleted.
61. What is OLTP?
Online Transaction Processing (OLTP) relational databases are optimal for managing
changing data. When several users are performing transactions at the same time,
OLTP databases are designed to let transactional applications write only the data
needed to handle a single transaction as quickly as possible.
62. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special
language called DDL.

63. What is Weak Entity set?
An entity set may not have sufficient attributes to form a primary key, and its
primary key compromises of its partial key and primary key of its parent entity, then
it is said to be Weak Entity set.
64. What is a deadlock?
Two processes wating to update the rows of a table which are locked by the other
process then deadlock arises.
65. What do you mean by flat file database?
It is a database in which there are no programs or user access languages. It has no
cross-file capabilities but is user-friendly and provides user-interface management.
66. What is Storage Manager?
It is a program module that provides the interface between the low-level data stored
in database, application programs and queries submitted to the system.
67. What is Index?
An index is a physical structure containing pointers to the data. Indices are created
in an existing table to locate rows more quickly and efficiently. It is possible to
create an index on one or more columns of a table, and each index is given a name.
68. What is the difference between clustered and a non-clustered index?
A Clustered index is a special type of index that reorders the way records in the
table are physically stored. Therefore table can have only one clustered index. The
leaf nodes of a clustered index contain the data pages.

A Nonclustered index is a special type of index in which the logical order of the
index does not match the physical stored order of the rows on disk. The leaf node of
a nonclustered index does not consist of the data pages. Instead, the leaf nodes
contain index rows.

69. What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
HAVING can be used only with the SELECT statement. HAVING is typically used in a
GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE
clause. Having Clause is basically used only with the GROUP BY function in a query.
WHERE Clause is applied to each row before they are part of the GROUP BY function
in a query.
70. What is log shipping?
Log shipping is the process of automating the backup of database and transaction
log files on a production SQL server, and then restoring them onto a standby server.
Enterprise Editions only supports log shipping. In log shipping the transactional log
file from one server is automatically updated into the backup database on the other
server.
71. What are primary keys and foreign keys?
Primary keys are the unique identifiers for each row. They must contain unique
values and cannot be null. Due to their importance in relational databases, Primary
keys are the most fundamental of all keys and constraints. A table can have only
one Primary key.
Foreign keys are both a method of ensuring data integrity and a manifestation of the
relationship between tables.
72. What are check constraint?
A Check constraint is used to limit the values that can be placed in a column. The
check constraints are used to enforce domain integrity.
96. What is Self Join?
A self join can be of any type, as long as the joined tables are the same. A self join
is rather unique in that it involves a relationship with only one table.
73. What are the type of Synonyms?
There are two types of Synonyms are :
Private
Public
74. What is an Integrity Constrains?
An integrity constraint is a declarative way to define a business rule for a column of
a table.

75. What is Table?
A table is the basic unit of data storage in an ORACLE database. The tables of a
database hold all of the user accessible data. Table data is stored in rows and
columns.
76. What is a synonym?
A synonym is an alias for a table, view, sequence or program unit.
77. What is Rollback Segment?
A Database contains one or more Rollback Segments to temporarily store "undo"
information.
78. What does COMMIT do?
A Commit makes permanent the changes resulting from all SQL statements in the
transaction. The changes made by the SQL statements of a transaction become
visible to other user sessions transactions that start only after transaction is
committed.
79. What is a Database instance?
A database instance (Server) is a set of memory structure and background
processes that access a set of database files.
80. What are Roles?
Roles are named groups of related privileges that are granted to users or other
roles.
81. What is SQLPlus?
SQLPlus is an application that recognizes & executes SQL commands & specialized
SQL*Plus commands that can customize reports, provide help & edit facility &
maintain system variables.
82. What is the difference between normalization and denormalization?
Normalizing data means eliminating redundant information from a table and
organizing the data so that future changes to the table are easier.

Denormalization means allowing redundancy in a table. The main benefit of
denormalization is improved performance with simplified data retrieval and
manipulation.
83. What is a trigger?
Triggers are stored procedures created in order to enforce integrity rules in a
database. A trigger is executed every time a data-modification operation occurs
(i.e., insert, update or delete).
Triggers are executed automatically on occurance of one of the data-modification
operations.
84. What is the difference between static and dynamic SQL?
Static SQL is hard-coded in a program when the programmer knows the statements
to be executed.
Dynamic SQL the program must dynamically allocate memory to receive the query
results.
85. What is UNIQUE KEY constraint?
A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so
no duplicate values are entered. The unique key constraints are used to enforce
entity integrity as the primary key constraints.
86. What is NOT NULL Constraint?
A NOT NULL constraint enforces that the column will not accept null values. The not
null constraints are used to enforce domain integrity, as the check constraints.

87. What is meant by query optimization?
The phase that identifies an efficient execution plan for evaluating a query that has
the least estimated cost is referred to as query optimization.
88. What is meant by embedded SQL?
They are SQL statements that are embedded with in application program and are
prepared during the program preparation process before the program is executed.
89. What is File Manager?
It is a program module, which manages the allocation of space on disk storage and
data structure used to represent information stored on a disk.
90. Define transaction?
A collection of operations that fom a single logical unit of works are called
transaction.
91. Define Constraints?
Constraints is a rule or restriction concerning a piece of data that is enforced at the
data level.
A Constraint clause can constrain a single column or group of columns in a table.
There are five types of Constraint namely
Null / Not Null
Primary Key
Unique
Check or Validation
Foreign Key or References Key
92. What are types of sub-queries?
Single-row subquery, where the subquery returns only one row.
Multiple-row subquery, where the subquery returns multiple rows.
Multiple column subquery, where the subquery returns multiple columns.
93. What is SQL Profiler?
SQL Profiler is a graphical tool that allows system administrators to monitor events
in an instance of Microsoft SQL Server. You can capture and save data about each
event to a file or SQL Server table to analyze later.
94. Define Clusters?
Clustering is a method of storing tables that are intimately related and often joined
together into the same area on disk.
A cluster contains one or more tables, which have one or more column in common
among them.
95. Define Indexes?
Index is a general term for an Oracle/SQL features used to primarily to speed
execution and imposes uniqueness upon certain data.
The most important of an index is to ensure uniqueness of rows and help in speedy
retrieval of data.
96. What is data integrity?
Data integrity is an important feature in SQL Server. When used properly, it ensures
that data is accurate, correct, and valid. It also acts as a trap for otherwise
undetectable bugs within applications.
97. What is De-normalization?
De-normalization is the process of attempting to optimize the performance of a
database by adding redundant data.
De-normalization is a technique to move from higher to lower normal forms of
database modeling in order to speed up database access.
98. What is referential integrity?
Referential integrity refers to the consistency that must be maintained between
primary and foreign keys, i.e. every foreign key value must have a corresponding
primary key value.
99. What is the difference between static and dynamic SQL?
Static SQL is hard-coded in a program when the programmer knows the statements
to be executed.
For dynamic SQL the program must dynamically allocate memory to receive the
query results.
100. Define Unique Key?
Unique key is a one or more column that must be unique for each row of the table.
It is similar to primary key. Primary key column will not accept a null. Whereas the
unique key column will accept a null values.
101. Define Synonym?
Synonym is an alternative method to creating a view that includes the entire table
or view from another user it to create a synonym.
A synonym is a name assigned to a table or view that may thereafter be used to
refer to it.
102. What is an Data Abtration?
A major purpose of a database system is to provide users with an abstract view of
the data.There are three levels of data abstraction
Physical level
Logical level
View level
103. What is Transaction Manager?
It is a program module, which ensures that database, remains in a consistent state
despite system failures and concurrent transaction execution proceeds without
conflicting.
104. What kind of User-Defined Functions can be created?
There are three types of User-Defined functions in SQL Server 2000 and they are
Scalar, Inline Table-Valued and Multi-statement Table-valued.
105. What are defaults? Is there a column to which a default can't be bound?
A default is a value that will be used by a column, if no value is supplied to that
column while inserting data. IDENTITY columns and timestamp columns can't have
defaults bound to them. See CREATE DEFUALT in books online.
106. What's the maximum size of a row?
8060 bytes. Don't be surprised with questions like what is the maximum number of
columns per table. Check out SQL Server books online for the page titled:
Maximum Capacity Specifications.
107. What is the difference between a local and a global variable?
A Local temporary table exists only for the duration of a connection or, if defined
inside a compound statement, for the duration of the compound statement.
A Global temporary table remains in the database permanently, but the rows exist
only within a given connection. When connection are closed, the data in the global
temporary table disappears. However, the table definition remains with the database
for access when database is opened next time.
108. What is a query?
A query with respect to DBMS relates to user commands that are used to interact
with a data base. The query language can be classified into data definition language
and data manipulation language.
109. What is Relational Algebra?
It is procedural query language. It consists of a set of operations that take one or
two relations as input and produce a new relation.
110. What is the difference between TRUNCATE and DELETE commands?
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE
operation can be rolled back, but TRUNCATE operation cannot be rolled back.
WHERE clause can be used with DELETE and not with TRUNCATE.
111. Describe the three levels of data abstraction?
There are three levels of abstraction :

Physical level :
The lowest level of abstraction describes how data are stored.
Logical level:
The next higher level of abstraction, describes what data are stored in database and
what relationship among those data.
View level:
The highest level of abstraction describes only part of entire database.
112. How to copy the tables, schema and views from one SQL server to another?
Microsoft SQL Server 2000 Data Transformation Services (DTS) is a set of graphical
tools and programmable objects that lets user extract, transform, and consolidate
data from disparate sources into single or multiple destinations.
113. What is the use of DESC in SQL?
DESC has two purposes.
It is used to describe a schema as well as to retrieve rows from table in descending
order.
114. What is a cluster Key?
The related columns of the tables are called the cluster key. The cluster key is
indexed using a cluster index and its value is stored only once for multiple tables in
the cluster.
115. Define candidate key, alternate key, composite key?
A candidate key is one that can identify each row of a table uniquely. Generally a
candidate key becomes the primary key of the table.

If the table has more than one candidate key, one of them will become the primary
key, and the rest are called alternate keys.

A key formed by combining at least two or more columns is called composite key.
116. What are the purpose of Normalisation?


Minimize redundancy in data.
Remove insert, delete and update anamoly during the database activities.
Reduce the need to reorganize data it is modified or enhanced.
Normalisation reduces a complex user view to a set of small and stable subgroups of
fields or relations.
117. What is RAID?
RAID, an acronym for Redundant Array of Independent Disks (sometimes incorrectly
referred to as Redundant Array of Inexpensive Disks), is a technology that provides
increased storage functions and reliability through redundancy.
118. What is database replication?
Replication is the process of copying / moving data between databases on the same
or different servers.
119. What are cursors?
Cursors allow row-by-row prcessing of the result sets.
120. What is a weak entity types?
The entity types that do not have key attributes of their own are called weak entity
types. Rests are called strong entity types .The entity that gives identity to a weak
entity is called owner entity. And the relationship is called identifying relationship. A
weak entity type always has a total participation constraint with respect to its
identifying relationship.
121. What are defaults?
A default is a value that will be used by a column, if no value is supplied to that
column while inserting data. IDENTITY columns and timestamp columns cant have
defaults bound to them.
122. What is specialization?
It is the process of defining a set of subclasses of an entity type where each
subclass contain all the attributes and relationships of the parent entity and may
have additional attributes and relationships which are specific to itself.
122. What are the different types of cursors?
Types of cursors :
Static
Dynamic
Forward-only
Keyset-driven
123. What is a Catalog?
A catalog is a table that contain the information such as structure of each file ,the
type and storage format of each data item and various constraints on the data .The
information stored in the catalog is called Metadata . Whenever a request is made to
access a particular data, the DBMS s/w refers to the catalog to determine the
structure of the file.
124. What is a view?
A view may be a subset of the database or it may contain virtual data that is derived
from the database files but is not explicitly stored.
125. What are different types of end users?
Casual end-users
Casual end-users
Sophisticated end users
Stand alone users
125. What is a data model?
It is a collection of concepts that can be used to describe the structure of a
database. It provides necessary means to achieve this abstraction. By structure of a
database we mean the data types, relations, and constraints that should hold on the
data.
126. What are types of schema?
Internal schema
Conceptual schema
External schema
127. What are different types of DBMS?
DBMS
RDBMS (Relational)
ORDBMS (Object Relational)
DDBMS (Distributed)
FDBMS (Federated)
FDBMS (Federated)
HDBMS (Hierarchical)
NDBMS (Networked)
128. What is a lock?
A lock is a variable associated with a data item that describes the status of the item
with respect to the possible operations that can be applied to it.

Anda mungkin juga menyukai