31. Describe how to handle errors in SQL.
UseTRY...CATCH blocks (in SQL Server) or exception handling constructs provided by the database to catch and manage runtime errors, ensuring graceful failure or rollback.32. What are temporary tables?
Temporary tables store intermediate results temporarily during a session or procedure, usually with names prefixed by
# (local) or ## (global) in SQL Server.33. Explain the difference between CHAR and VARCHAR.
⦁
CHAR is fixed-length and pads unused spaces, faster for fixed-size data.⦁
VARCHAR is variable-length, saves space for variable data but may be slightly slower.34. How do you perform pagination in SQL?
Use
LIMIT and OFFSET (MySQL/PostgreSQL):Or in SQL Server:
35. What is a composite key?
A primary key made up of two or more columns that uniquely identify a record.
36. How do you convert data types in SQL?
Using
CAST() or CONVERT() functions, e.g.,37. Explain locking and isolation levels in SQL.
Locks control concurrent access to data. Isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) define visibility of changes between concurrent transactions, balancing consistency and performance.
38. How do you write recursive queries?
Using Recursive CTEs with
WITH clause:39. What are the advantages of using prepared statements?
Improved performance (query plan reuse), security (prevents SQL injection), and ease of use with parameterized inputs.
40. How to debug SQL queries?
Analyze execution plans, check syntax errors, use descriptive aliases, test subqueries separately, and monitor performance metrics.
No comments:
Post a Comment