SQL Reference

Links : Learn     Interview Questions     IDE
            

SQL Interview Questions - Page 1

Next Page >
Question: What is SQL?
Answer: SQL stands for Structured Query Language. It is a standardized programming language used to manage and manipulate relational databases.
SQL allows users to query, insert, update, and delete data, as well as define and modify database structures such as tables, indexes, and views.

Question: What is a primary key?
Answer: A primary key is a column or a set of columns that uniquely identifies each row in a table. It ensures that each row in the table is uniquely identifiable and that no two rows can have the same primary key value.
Primary keys are used to enforce entity integrity in a relational database.

Question: What is a foreign key?
Answer: A foreign key is a column or a set of columns in a table whose values match the primary key in another table.
It establishes a link between two tables, enforcing referential integrity in the database.

Question: What is a 'stored procedure'?
Answer: A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again.
It helps to reduce the amount of redundant SQL code in an application.

Question: What is a view in SQL?
Answer: A view is a virtual table based on the result set of a SELECT query. It does not store any data itself but presents data from one or more underlying tables.
Views can simplify complex queries and provide an additional layer of security by restricting access to certain columns or rows.

Question: What is normalization in SQL and why is it important?
Answer: The normalization is the process of organizing data in a database efficiently. It involves dividing a database into two or more tables and defining relationships between them to minimize redundancy and dependency.
Normalization helps to eliminate insertion, update, and deletion anomalies and ensures data integrity.

Question: Can you explain the difference between DELETE and TRUNCATE in SQL?
Answer: The DELETE is a DML (Data Manipulation Language) command used to remove rows from a table based on a condition.
And TRUNCATE is a DDL (Data Definition Language) command used to remove all rows from a table, but it does not log individual row deletions and is faster than DELETE.

Question: What is the difference between GROUP BY and ORDER BY in SQL?
Answer: The GROUP BY is used to group rows that have the same values into summary rows, typically for use with aggregate functions like COUNT(), SUM(), AVG(), etc. ORDER BY, on the other hand, is used to sort the result set in ascending or descending order based on one or more columns.

Question: What is the difference between the HAVING clause and the WHERE clause in SQL?
Answer: The WHERE clause is used to filter rows before any grouping is done in a query, while the HAVING clause is used to filter rows after the grouping has occurred, typically when using aggregate functions with GROUP BY.

Next Page >