Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

SQL Interview Questions by Skill Arbitrage

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

SQL Interview Questions by Skill Arbitrage

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL Interview Questions and Answers

1. What is SQL and its main features?


SQL is the language used to interact with databases. It helps in retrieving, adding, updating,
and deleting data. Key features include querying data (SELECT), modifying data (INSERT,
UPDATE, DELETE), and managing the database structure (CREATE, ALTER, DROP).

2. Order of writing SQL query?


- SELECT (what data you want)
- FROM (where it’s from)
- WHERE (filter the rows)
- GROUP BY (group similar data)
- HAVING (filter groups)
- ORDER BY (sort the results).

3. Order of execution of SQL query?


SQL runs in this order:
- FROM (choose the table)
- JOIN (combine tables)
- WHERE (apply filters)
- GROUP BY (group results)
- HAVING (filter groups)
- SELECT (choose columns)
- ORDER BY (sort results).

4. Common SQL commands?


- SELECT: Get data.
- INSERT: Add new data.
- UPDATE: Modify data.
- DELETE: Remove data.
- CREATE: Make a new table or database.
- ALTER: Change an existing table.
- DROP: Delete a table or database.

5. Primary key vs. Foreign key?


- Primary Key: Uniquely identifies each row in a table.
- Foreign Key: Links one table to another, referencing the primary key in the other table.
6. Types of joins?
- INNER JOIN: Returns matching data in both tables.
- LEFT JOIN: Returns all data from the left table, even if no match in the right.
- RIGHT JOIN: Returns all data from the right table, even if no match in the left.
- FULL JOIN: Returns all data from both tables, with NULL where there’s no match.
- CROSS JOIN: Combines every row from both tables.

7. Window functions?
- ROW_NUMBER(): Number each row.
- RANK(): Assign ranks with gaps for ties.
- DENSE_RANK(): Similar to rank, but no gaps.
- LEAD()/LAG(): Get data from the next/previous row.

8. What is a stored procedure?


A stored procedure is a reusable set of SQL commands that you can run like a program, great
for repetitive tasks.

9. Difference between stored procedure & functions?


- Stored Procedures: Can return multiple values, modify data, and use output parameters.
- Functions: Always return a single value and can’t change data directly.

10. What is a trigger?


A trigger is an automatic action in the database that runs when you insert, update, or delete
data.

11. WHERE vs HAVING?


- WHERE: Filters rows before grouping.
- HAVING: Filters after grouping, often used with aggregates like COUNT() or SUM().

You might also like