DISTINCT Keyword
The DISTINCT
keyword is used in SQL queries to eliminate duplicate rows from the result set. It ensures that the query returns only unique records from the specified columns.
Example ====>>>
SELECT DISTINCT column_name FROM table_name;
NOLOCK Hint (Non-locking Reads)
The NOLOCK hint in SQL Server is used to perform dirty reads on the database, meaning it allows the query to read data without placing any locks on the data. This means that other transactions can modify the data while the query is running, and the query can still read it, even if it hasn't been committed yet.
Example ===>>>>>
SELECT * FROM table_name WITH (NOLOCK);
Advantages:
Improved Performance: Since NOLOCK avoids placing locks, it can reduce contention and improve performance, especially for read-heavy queries in high-concurrency environments.
Faster Queries: Particularly in reporting and data warehousing environments where reading large amounts of data without waiting for locks is crucial, it can provide faster response times.
Disadvantages:
Dirty Reads: The query can return uncommitted data (data that might later be rolled back), leading to inaccurate or inconsistent results
No comments:
Post a Comment