Top 26 SQL Interview Questions and Answers

Top 26 SQL Interview Questions and Answers
  1. What is SQL?

SQL means structured query language. It is a database language used for database creation, updating and deletion, fetching and modifying rows.

  1. When SQL appeared?

It appeared in the year 1974.

  1. What are the usages of SQL?

To execute queries against a database, retrieve data from a database, inserting records, updates records in a database, and deletes records from a database, to create new databases

  1. Which is the subset of SQL?
  • Data definition language (DDL)
  • Data manipulation language (DML)
  • Data control language (DCL)
  1. What is data definition language?

Data definition language (DDL) allows the user to CREATE, ALTER and DELETE database objects such as tables, view, sequence, etc.

  1. What is data manipulation language?

Data manipulation language is used to manipulate the data

  • Insert data into a database
  • Update data in the database
  • Delete data from the database
  1. What is data control language?

Data control language allows the user to control/grant access to the database. It includes two commands GRANT and revokes.

GRANT: to grant the specific user to perform a specific task.

REVOKE: to cancel previously denied or granted permissions.

 

  1. What are tables and fields in the database?

A table is a set of organized data. It has columns and rows. Columns can be categorized as vertical, and Rows are horizontal.Together they form a cell in which data can be filled

A table contains a specified number of a column called fields but can have any number of rows which is known as a record.

  1. What is a primary key?

A primary key is a great combination of fields which can uniquely specify a row. It is unique in nature.This is a unique key, and it is valued cannot be NULL.

  1. What is a foreign key?

A foreign key is associated with the primary key of another table. A relationship needs to be created between two tables by referencing foreign key with the primary key of another table. Thus primary key of other tables becomes foreign key for another table

  1. What is a unique key?

A Unique key means it uniquely identifies each record in the database. This provides uniqueness in the column or set of columns. The unique key can be null.

  1. What is the type of operators available in SQL?
  • Arithmetic operators
  • Logical operators
  • Comparison operator
  • Conditional operator
  1. What is an Index in SQL?

The index is used to increase the performance and help for faster retrieval of records from the table. An index also creates an entry for each value, and it is also faster to retrieve data and for performing search operations

  1. Which are the different types of indexes in SQL?

Three types of Indexes are:

  • Unique Index
  • Clustered Index
  • NonClustered Index
  1. State the difference between SQL and PL/SQL?

SQL is a language which helps to communicate with a relational database. It provides a way to define, manipulate and create databases.  PL/SQL is an advance version 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. 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 lesser space to store. View can have data of more than one table, and it depends on the relationship between the tables.

  1. Which are the most commonly SQL joins?

Two commonly used SQL joins are INNER JOIN and  OUTER JOIN.

 

  1. What are the different types of joins in SQL?

Joins are used to merge two tables or retrieve data from tables. It depends on the relationship between tables.

  1. Following are the most commonly used joins in SQL:
  • Inner Join
  • Right Join
  • Left Join
  • Full Join
  1. What is Inner Join in SQL?

Inner join:

Inner join returns rows when there is at least one match of rows between the tables.

  1. What is Unique Index?

Unique Index does not have duplicate values in case if the column is unique indexed. A unique index can be applied automatically when the primary key is defined in any table.

  1. 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 define, 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 for performing operations.

 

  1. What is Right Join in SQL?

Right Join:

Right, join is used to return rows which are common between the tables. It returns all the rows from the right-hand side table even though there are no matches in the left-hand side table.

  1. What is Left Join in SQL?

Left Join:

A 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 Left-hand side table even though there are no matches in the Right-hand side table.

  1. What is Full Join in SQL?

Full Join:

It returns rows when there are matching rows. It also shows all the rows from the left-hand side table and all the rows from the right-hand side table. It is like union of tables

  1. What is “TRIGGER” in SQL?

The trigger allows the user to execute a batch of SQL code whenever an insert, update or delete command is executed for a specific table. Triggers work on DML query. Triggers are special type of stored procedures that are defined to execute automatically in place or after data modifications.

Leave a Reply

Close Menu