What is SQL?
SQL stands for Structured Query Language, and it is used to communicate with the Database. This is a standard language used to perform tasks such as retrieval, updation, insertion and deletion of data from a database.
What are the usages of SQL?
- To execute queries against a database
- To retrieve data from a database
- To inserts records in a database
- To updates records in a database
- To delete records from a database
- To create new databases
- To create new tables in a database
- To create views in a database
What is the difference between SQL and MySQL?
SQL or Structured Query Language is a language; language that communicates with a relational database thus providing ways of manipulating and creating databases. MySQL and Microsoft’s SQL Server both are relational database management systems that use SQL as their standard relational database language.
What is the difference between SQL and PL/SQL?
PL/SQL is a dialect of SQL that adds procedural features of programming languages in SQL. It was developed by Oracle Corporation in the early 90’s to enhance the capabilities of SQL.
What are the subsets of SQL?
- Data definition language (DDL)
- Data manipulation language (DML)
- Data control language (DCL)
What is data definition language?
Data definition language(DDL) allows you to CREATE, ALTER and DELETE database objects such as schema, tables, view, sequence etc.
What are various DDL commands in SQL? Give brief description of their purposes.
Following are various DDL or Data Definition Language commands in SQL −
- CREATE − it creates a new table, a view of a table, or other object in database.
- ALTER − it modifies an existing database object, such as a table.
- DROP − it deletes an entire table, a view of a table or other object in the database.
What is data manipulation language?
Data manipulation language makes user able to access and manipulate data. It is used to perform following operations.
- Insert data into database
- Retrieve data from the database
- Update data in the database
- Delete data from the database
What are various DML commands in SQL? Give brief description of their purposes.
Following are various DML or Data Manipulation Language commands in SQL −
- SELECT − it retrieves certain records from one or more tables.
- INSERT − it creates a record.
- UPDATE − it modifies records.
- DELETE − it deletes records.
What is the purpose of DML statements in SQL?
The DML statements are used to add new rows to a table, update or modify data in existing rows, or remove existing rows from a table.
What is data control language?
Data control language allows you to control access to the database. It includes two commands GRANT and REVOKE.
- GRANT: to grant specific user to perform specific task.
- REVOKE: to cancel previously denied or granted permissions.
What are the type of operators available in SQL?
- Arithmetic operators
- Logical operators
- Comparison operator
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 are 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.
What is the purpose of the condition operators BETWEEN and IN?
The BETWEEN operator displays rows based on a range of values. The IN condition operator checks for values contained in a specific set of values.
What are the specific uses of SQL functions?
SQL functions have the following uses −
- Performing calculations on data
- Modifying individual data items
- Manipulating the output
- Formatting dates and numbers
- Converting data types
What are the case manipulation functions of SQL?
What is the difference between cross joins and natural joins?
The cross join produces the cross product or Cartesian product of two tables. The natural join is based on all the columns having same name and data types in both the tables.
What is a view? Why should you use a view?
A view is a logical snapshot based on a table or another view. It is used for −
- Restricting access to data;
- Making complex queries simple;
- Ensuring data independency;
- Providing different views of same data.
What is the difference between VARCHAR2 AND CHAR data types?
VARCHAR2 represents variable length character data, whereas CHAR represents fixed length character data.
What is the purpose of the MERGE statement in SQL?
The MERGE statement allows conditional update or insertion of data into a database table. It performs an UPDATE if the rows exist, or an INSERT if the row does not exist.
How do you copy rows from one table to another?
The INSERT statement can be used to add rows to a table by copying from another table. In this case, a subquery is used in the place of the VALUES clause.
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, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.
What is a unique key?
A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.
A Primary key constraint has automatic unique constraint defined on it. But not, in the case of Unique Key.
There can be many unique constraints defined per table, but only one Primary key constraint defined per table.
2024 SQL Interview Questions and Answers
What is a foreign key?
A foreign key is one table which can be 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.
What is a join?
This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.
What is normalization?
Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.
What is Denormalization?
Denormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.