This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
PRIMARY KEY and UNIQUE: What is the difference?
Clustered vs Non-Clustered Index: What is the simple way?
What is the full syntax of a SELECT query?
RANK, DENSE_RANK, ROW_NUMBER: what is the simple difference?
How can you performance tune a Stored Procedure?
- Use column names instead of * in SELECT query
- Reduce the use of temp tables created in the SP, delete the tables once their use is over.
- Create indexes on frequently queried columns,
- use JOIN statements instead of sub-queries or correlated sub-queries.
How do you throw custom errors in SQL
We can use raiseError to throw custom exceptions in an P-SQL block.
Example:
RAISERROR (N'Error Raised: %s %d.', -- Message text.
10, -- Severity,
1, -- State,
N'number', -- First argument from the
5); -- Second argument.
Returns Error Message: Error Raised: number 5.
What are DQL commands?
DQL or Data Query Language commands are used for querying data from database objects. This is only a single command which can result in records from dbo such as tables, views etc and can be subject to projection.
SELECT [ DISTINCT column_1, column_2 .. | * ]
FROM <table_name>
WHERE <query_condition>
GROUP BY <columns_list>
HAVING <condition>
ORDER BY <columns_list> [ ASC | DESC ]
What are TCL commands?
TCL or Transaction Control Language commands are used to enforce control on transactions within a database object which might result in a change in the state of data within the dbo.
These are:
- COMMIT
- ROLLBACK [ TO save_point_name ]
- SAVEPOINT save_point_name