SQL Interview Question1
SQL Interview Question1
There is given sql interview questions and answers that has been asked in many companies.
For PL/SQL interview questions, visit our next page.
1) What is SQL?
SQL stands for structured query language. It is a database language used for database
creation, deletion, fetching rows and modifying rows etc. sometimes it is pronounced as se-
qwell.
A table contains specified number of column called fields but can have any number of rows
which is known as record.
10) What is a primary key?
A primary key is a combination of fields which uniquely specify a row. This is a special kind of
unique key. Primary key values cannot be NULL.
1. Arithmetic operators
2. Logical operators
3. Comparison operator
o Unique Index
o Clustered Index
o NonClustered Index
This indexing does not allow the field to have duplicate values if the column is unique indexed.
Unique index can be applied automatically when primary key is defined.
The clustered index is used to reorder the physical order of the table and search based on the
key values. Each table can have only one clustered index.
NonClustered Index does not alter the physical order of the table and maintains logical order
of data. Each table can have 999 non-clustered indexes.
20) What is the difference between SQL, MySQL and SQL Server?
SQL or Structured Query Language is a language which is used to communicate with a
relational database. It provides a way to manipulate and create databases. On the other hand,
MySQL and Microsoft's SQL Server both are relational database management systems that
use SQL as their standard relational database language.
21) What is the difference between SQL and PL/SQL?
SQL or Structured Query Language is a language which is used to communicate with a
relational database. It provides a way to manipulate and create databases. On the other hand,
PL/SQL is a dialect of SQL which is used to enhance the capabilities of SQL. It was developed
by Oracle Corporation in the early 90's. It adds procedural features of programming languages
in SQL.
1. One table can have only one clustered index but it can have many non clustered
index.(approximately 250).
2. clustered index determines how data is stored physically in table. Actually clustered
index stores data in cluster, related data is stored together so it makes simple to
retrieve data.
3. reading from a clustered index is much faster than reading from non clustered index
from the same table.
4. clustered index sort and store data rows in the table or view based on their key value,
while non cluster have a structure separate from the data row.
o Inner Join
o Right Join
o Left Join
o Full Join
Inner join returns rows when there is at least one match of rows between the tables.
Right join is used to retrieve rows which are common between the tables and all rows of Right
hand side table. It returns all the rows from the right hand side table even though there are
no matches in the left hand side table.
Left join is used to retrieve rows which are common between the tables and all rows of Left
hand side table. It returns all the rows from Left hand side table even though there are no
matches in the Right hand side table.
30) What is Full Join in SQL?
Full Join:
Full join return rows when there are matching rows in any one of the tables. This means, it
returns all the rows from the left hand side table and all the rows from the right hand side
table.
Actually triggers are special type of stored procedures that are defined to execute
automatically in place or after data modifications.
32) What is self join and what is the requirement of self join?
Self join is often very useful to convert a hierarchical structure to a flat structure. It is used
to join a table to itself as like if that is the second table.
36) Write an SQL query to find names of employee start with 'A'?
2) We can use WHERE clause in DELETE command. We cannot use WHERE clause with TR
3) DELETE statement is used to delete a row from a TRUNCATE statement is used to remov
table a table.
Atomicity: it requires that each transaction is all or nothing. It means if one part of the
transaction fails, the entire transaction fails and the database state is left unchanged.
Consistency: the consistency property ensure that the data must meet all validation rules.
In simple words you can say that your transaction never leaves your database without
completing its state.
Isolation: this property ensure that the concurrent property of execution should not be met.
The main goal of providing isolation is concurrency control.
Durability: durability simply means that once a transaction has been committed, it will
remain so, come what may even power loss, crashes or errors.
40) What is the difference among NULL value, zero and blank
space?
Ans: A NULL value is not same as zero or a blank space. A NULL value is a value which is
'unavailable, unassigned, unknown or not applicable'. On the other hand, zero is a number
and blank space is treated as a character.
o LOWER
o UPPER
o INITCAP
The COALESCE function is used to return the first non-null expression given in the parameter
list.