Top 20 SQL basic beginner level Interview Questions
1. What is SQL?
SQL (Structured Query Language) is a standard language used to manage and manipulate relational databases. It allows users to create, read, update, or delete data, provides structured queries, and is easy to understand to perform these operations effectively. Almost all data-driven applications depend on SQL to store and retrieve the data.
2.What is a database?
A database is a systematically organized data collection and typically stored in a table format consisting of rows and columns. A Database Management system (DBMS) helps to manage storage, manipulation, and retrieval of data
3. What are the various types of SQL commands?
The various types of SQL commands are :
DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE.
DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE.
DCL (Data Control Language): GRANT, REVOKE.
TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT.
4.What is the Primary Key?
A Primary Key is used to avoid duplication of data in a table, whose values uniquely identify a row in the table. It ensures that no two rows have the same value in the primary key column(s), and it does not allow NULL values.
5. What is Foreign Key?
A Foreign key is a set of attributes in a table that refers to the primary key of another table. It establishes and enforces a relationship between the two tables, ensuring data integrity.
Finding these SQL questions useful?
subscribing to my newsletter for more beginner-friendly tech tips, interview questions, and job prep content delivered straight to your inbox!
👉 [Subscribe Now] & stay ahead.
6. What is the difference between Primary Key and Unique Key?
Primary Key CREATE TABLE Employees ( EmpID INT PRIMARY KEY, Name VARCHAR(100) );
Unique Key CREATE TABLE Users ( UserID INT PRIMARY KEY, Email VARCHAR(100) UNIQUE );
7. What is the difference between CHAR and VARCHAR data types?
CHAR: It stores data in fixed-length storage. If the input is smaller than the defined size, it is padded with spaces. VARCHAR2: It stores data with variable length storage. It uses space only for the actual data storage, making it more storage-efficient for shorter values.
8. What is normalization?
Normalization is the process of structuring data in a database to reduce duplication and enhance data integrity. It helps to minimize large tables into smaller, related tables and establish relationships between them to maintain consistency and avoid anomalies.
9.What is the purpose of the DEFAULT constraint?
When no value is specified during an INSERT operation, the DEFAULT constraint automatically assigns a default value to a column. This helps to maintain consistency and enhances data entry efficiency.
10. What are the different operators in SQL?
11.What are the different types of joins in SQL?
INNER JOIN: It returns only the matching rows from both tables.
LEFT JOIN (or LEFT OUTER JOIN):Returns all rows from the left table and the matching rows from the right table.If there is no match, NULLs are shown for right table columns.
RIGHT JOIN (or RIGHT OUTER JOIN):Returns all rows from the right table and matching rows from the left table.If there is no match, NULLs are shown for left table columns.
FULL JOIN (or FULL OUTER JOIN):Returns all rows from both tables.
CROSS JOIN: Returns the Cartesian product of both tables
Recommended by LinkedIn
12. What are aggregate functions in SQL?
Aggregate functions perform calculations and return a single result based on a group or set of values The aggregate functions include:
Hey, you're halfway through awesome! If you're enjoying this content, I’d love to keep in touch.👉 Follow me for more practical SQL tips, and subscribing to my newsletter for regular updates!
13. What is the difference between DELETE , DROP and TRUNCATE commands?
DELETE Command: Delete rows individually and records each deletion in the transaction log, making rollback possible. It can have a WHERE clause to delete specific records.
DROP Command: It completely removes the table structure and its data from the database. Once DROP Command is executed, the table is permanently deleted and can't be recovered unless restored from a backup.
TRUNCATE Command: It quickly removes all the rows from the table at once without logging each row deletion. It does not support a WHERE clause and is faster than DELETE for large datasets.
14. What are the types of constraints in SQL?
Constraints are applied to table columns to enforce data integrity and improves accuracy in a database.
NOT NULL: Ensures that a column cannot have NULL values.
UNIQUE: Ensures that all values in a column are different . (no duplicates).
PRIMARY KEY: Uniquely identifies each row in a table.
FOREIGN KEY: Maintains referential integrity by linking to a primary key in another table.
CHECK: Ensures that all values in a column meet a specific condition.
DEFAULT: Assigns a default value for a column, if no value is specified.
15. What are the differences between SQL and NoSQL databases? SQL Databases:
NoSQL Databases:
16. What is a subquery?
A subquery is a query nested within the another query, typically used in the WHERE , FROM, or SELECT clause to filter or retrieve data based on the results of another query, making it easier to handle complex filtering
17. What is Stored Procedure?
Stored Procedures are created to perform one or more DML operators on the database. It is nothing but a group of SQL Statements that accepts some input in the form of parameters, performs some tasks, and may or may not return a value.
18.What is the difference between the WHERE and HAVING clauses?
WHERE clause: It is used to filter records before any grouping takes place and applying conditions to individual rows.
HAVING clause: It is used to filter data after the GROUP BY clause and applying conditions to groups of rows
19. What is a cursor?
A cursor is a database object used to retrieve and manipulate rows from a query result one at a time.
Used in stored procedures and loops to process individual rows.
Example in SQL:
DECLARE cursor_name CURSOR FOR
SELECT name FROM students;
20. What is a trigger in SQL?
Trigger is a special type of stored procedure that automatically runs when an event occurs in the database server. DML triggers run when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view. If you found these questions helpful, there’s a lot more where that came from!
Follow for such topics on SQL, data careers, and tech interviews and get insider tips straight to your inbox by subscribing to my newsletter
👇 Bonus for early readers: Drop a 💬 below if you want a PDF version of these 20 SQL questions. I’ll send it your way! Or let me know which SQL topic you want me to cover next: Joins Subqueries Real-time project scenarios Optimization techniques Let’s grow together. 🚀