SQL Questions Answers
SQL Questions Answers
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.
It appeared in 1974.
No, SQL doesn't have loop or Conditional statement. It is used like commanding
language to access databases.
Data definition language(DDL) allows you to CREATE, ALTER and DELETE database
objects such as schema, tables, view, sequence etc.
Data manipulation language makes user able to access and manipulate data. It is
used to perform following operations.
Data control language allows you to control access to the database. It includes two
commands GRANT and REVOKE.
A table is a set of organized data. It has columns and rows. Columns can be
categorized as vertical, and Rows are horizontal.
A table contains specified number of column called fields but can have any number
of rows which is known as record.
A foreign key is specified as a key which is related to the primary key of another
table. Relationship needs to be created between two tables by referencing foreign
key with the primary key of another table.
A Unique key constraint uniquely identifies each record in the database. This
provides uniqueness for the column or set of columns.
Arithmetic operators
Logical operators
Comparison operator
14) What is view in SQL?
A view is a virtual table which contains a subset of data within a table. Views are
not virtually present, and it takes less space to store. View can have data of one
or more tables combined, and it is depending on the relationship.
Index is used to increase the performance and allow faster retrieval of records
from the table. An index creates an entry for each value and it will be faster to
retrieve data.
Unique Index
Clustered Index
NonClustered Index
17) What is Unique Index?
Unique 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.
Clustered Index:
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.
19) What is NonClustered Index in SQL?
NonClustered 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?
Yes. You can use column alias in the ORDER BY clause for sorting.
23) What is the difference between clustered and non clustered index in SQL?
There are mainly two type of indexes in SQL, Clustered index and non clustered
index. The differences between these two indexes is very important from SQL
performance perspective.
One table can have only one clustered index but it can have many non clustered
index.(approximately 250).
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.
reading from a clustered index is much faster than reading from non clustered index
from the same table.
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.
24) What is the SQL query to display current date?
Most commonly used SQL joins are INNER JOIN and (left/right) OUTER JOIN.
Joins are used to merge two tables or retrieve data from tables. It depends on the
relationship between tables.
Inner Join
Right Join
Left Join
Full Join
27) What is Inner Join in SQL?
Inner join:
Inner join returns rows when there is at least one match of rows between the
tables.
Right Join:
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:
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.
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.
Trigger allows you to execute a batch of SQL code when an insert, update or delete
command is executed against a specific 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?
The BETWEEN operator is used to display rows based on a range of values. The IN
condition operator is used to check for values contained in a specific set of
values.
The main differences between SQL DELETE and TRUNCATE statements are given below:
ACID property is used to ensure that the data transactions are processed reliably
in a database system.
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.
41) What is the usage of SQL functions?
LOWER
UPPER
INITCAP
43) What is the usage of NVL function?
The DISTINCT keyword is used to ensure that the fetched value is only a non-
duplicate value.