Category: T-SQL Fundamentals
-
View the Definition of a Stored Procedure in SQL Server
Three ways to read the source of a stored procedure, and the trap in all of them: without VIEW DEFINITION, OBJECT_DEFINITION returns NULL rather than an error, which looks exactly like the procedure does not exist.
Written by
-
RAND() vs NEWID() in SQL Server
Most people searching for “random numbers in SQL Server” want one of two things: SQL Server gives you two common tools for this: RAND() and NEWID(). They solve different problems, and confusion usually starts when they are treated as interchangeable. This post shows how to use both, starting with simple examples, and explains why they…
Written by
-
Create a Linked Server to Another SQL Server
Two stored procedures create a linked server, and on a modern instance the first attempt usually fails with a certificate error because MSOLEDBSQL 19 encrypts by default. The fix, plus rpc out, OPENQUERY, Msg 7411 and Msg 7202.
Written by
-
DROP TABLE IF EXISTS in SQL Server
DROP TABLE IF EXISTS arrived in SQL Server 2016 and replaced a three-line OBJECT_ID check that everybody had memorised. It is a small feature and it is genuinely useful, but there is more behaviour hiding in it than the syntax suggests.
Written by
-
How to Search for a String in All Tables in SQL Server
Somebody hands you a database you have never seen and a value: an email address, a reference code, a customer name. Where is it stored? There is no Ctrl+F for a schema, so the job is to build one.
Written by
-
How to Delete Duplicate Rows in SQL Server
Every DBA hits this one eventually. A table has two or more rows that are identical in every column that matters, and you need to remove all but one of them. An ETL job re-ran without a dedupe check. An import script fired twice. A missing unique constraint let bad data in through the front…
Written by
-
What WITH (NOLOCK) Actually Does in SQL Server
Almost every SQL Server developer has copied WITH (NOLOCK) onto the end of a query at some point, usually because someone said it “makes queries faster” or “avoids blocking.” Both of those things are technically true. What rarely gets explained is what you’re trading away to get them. WITH (NOLOCK) doesn’t make a query faster…
Written by
-
Difference Between DELETE and TRUNCATE in SQL Server
When someone asks: “What’s the difference between DELETE and TRUNCATE?” Most answers stop at: That is technically correct. It is also not enough. In production environments, choosing between DELETE and TRUNCATE is not about syntax. It is about: This post focuses on the production impact, not the textbook answer. Quick Technical Comparison Feature DELETE TRUNCATE…
Written by
-
Get Current Date & Time in SQL Server
Getting the current date and time in SQL Server is straightforward. Choosing the correct function for your workload is what matters. Whether you’re stamping audit rows, logging ETL runs, or investigating production issues, SQL Server exposes several built-in functions with different precision and return types. All of these functions use the Windows OS clock of…
Written by
-
How to Kill a SPID in SQL Server
In SQL Server, every connection to the database engine is assigned a Session Process ID, commonly known as a SPID. There are situations where you may need to kill a SPID in SQL Server. This typically occurs when a session is blocking other queries, running indefinitely, holding locks during maintenance, or preventing a database from…
Written by
- RESOURCE_SEMAPHORE When SQL Server Is Nowhere Near Its Memory Cap
- Dynamic Data Masking: What a WHERE Clause Still Reveals
- DBA Scripts: Get Log Shipping Status
- SQL Server Row-Level Security: The Filter Does Not Stop Cross-Tenant Writes
- View the Definition of a Stored Procedure in SQL Server
- TempDB Is Full or Still Growing: Find What Is Using It, Right Now
- Backups & Recovery (17)
- DBA Scripts (152)
- High Availability (HA) (13)
- Installation & Configuration (49)
- Maintenance (25)
- Migration & Upgrades (14)
- Monitoring (9)
- Performance Tuning (37)
- Security (Encryption & Permissions) (21)
- Storage & Capacity (16)
- T-SQL Fundamentals (15)
- Troubleshooting (95)
- Wait Types (235)