SQL Interview Question Must Learn
SQL Interview Question Must Learn
SQL stands for the Structured Query Language. SQL is a standard query
language used for maintaining the relational database and perform many
different operations of data manipulation on the data. SQL initially was
invented in 1970. It is a database language used for database creation,
deletion, fetching rows and modifying rows, etc. sometimes it is
pronounced as 'sequel.'
Primary key carries unique value but the field of the primary key cannot
be Null on the other hand unique key also carry unique value but it can
have a single Null value field.
14) What is a Database?
A Database is an organized form of data. The database is the electronic
system which makes data access, data manipulation, data retrieval, data
storing and data management very easy and structured. Almost every
organization uses the database for storing the data due to its easily
accessible and high operational ease. The database provides perfect
access to data and lets us perform required tasks.
Object-oriented databases
RDBMS is one of the most often used databases due to its easy
accessibility and supports regarding complex queries.
17) What is RDBMS?
RDBMS stands for Relational Database Management System. It is a
database management system based on a relational model. RDBMS stores
the data into the collection of tables and links those table using the
relational operators easily whenever required. It facilitates you to
manipulate the data stored in the tables by using relational operators.
Examples of the relational database management system are Microsoft
Access, MySQL, SQLServer, Oracle database, etc.
Due to redundant terms inconsistency may also occur id any change will
be made in the data of one table but not made in the same data of
another table then inconsistency will take place, which will lead to the
maintenance problem and effects the ACID properties as well.
Logical operators: ALL, AND, ANY, ISNULL, EXISTS, BETWEEN, IN, LIKE,
NOT, OR, UNIQUE.
Comparison operator: =, !=, <>, <, >, <=, >=, !<, !>
24) What is view in SQL?
A view is a virtual table which contains a subset of data within a table.
Views are not originally present, and it takes less space to store. A view
can have data from one or more tables combined, and it depends on the
relationship. Views are used to apply security mechanism in the SQL
Server. The view of the database is the searchable object we can use a
query to search the view as we use for the table.
Unique Index
Clustered Index
NonClustered Index
Bit-Map index
Normal index
Composite index
B-tree index
For creating a unique index, the user has to check the data in the column
because the unique indexes are used when any column of the table has
unique values. This indexing does not allow the field to have duplicate
values if the column is unique indexed. A unique index can be applied
automatically when a 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. The Clustered index is the only index which has been automatically
created when the primary key is generated. If moderate data modification
needed to be done in the table then clustered indexes are preferred.
MySQL is available for free as it is open source whereas SQL server is not
an open source software.
31) 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.
SQL is like the source of data that we need to display on the other hand
PL/SQL provides a platform where the SQL the SQL data will be shown.
One table can have only one clustered index, but it can have many non-
clustered index. (Approximately 250).
Reading from a clustered index is much faster than reading from non-
clustered index from the same table.
Clustered index sort and store data row in the table or view based on
their key value, while non-cluster has a structure separate from the data
row.
Theta join
Natural join
Equijoin
Inner join returns rows when there is at least one match of rows between
the tables. INNER JOIN keyword joins the matching records from two
tables.
INNER JOIN
Right Join is used to retrieve rows which are common between the tables
and all rows of a 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.
RIGHT JOIN
The left join is used to retrieve rows which are common between the
tables and all rows of the Left-hand side table. It returns all the rows from
the Left-hand side table even though there are no matches on the Right-
hand side table.
LEFT JOIN
The trigger is said to be activated when these commands are given to the
system.
Triggers are the particular type of stored procedures that are defined to
execute automatically in place or after data modifications.
Union, Union All, Intersect or Minus operators are the set operators
used in the SQL.
FROM (
5) You can rollback data after using It is not possible to rollback after
DELETE statement. using TRUNCATE statement.
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.
The NULL value can be treated as unknown and missing value as well, but
zero and blank spaces are different from the NULL value.
Case manipulation function can be used in almost every part of the SQL
statement.
Case manipulation functions are mostly used when you need to search for
data, and you don?t have any idea that the data you are looking for is in
lower case or upper case.
One or more than one characters and words should be passed into the
function, and then the function will perform its operation on those words.
TRIM: remove all the defined character from the beginning, end or both
beginning and end.
Instead of NVL() function MySQL have IFNULL() and SQL Server have
ISNULL() function.