Category: T-SQL Fundamentals
-
Move a Table to Another Schema in SQL Server
ALTER SCHEMA TRANSFER moves a table in one statement and drops every permission on it. What to script first, what blocks it (Msg 15348, 15151), and how to rename a schema.
Written by
-
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
A table has rows that should exist once and now exist two or three times: a load ran twice, an import fired again, and nothing on the table stopped it. Two queries fix it. A GROUP BY shows you the duplicate sets, and a ROW_NUMBER() delete removes every copy except one, whether or not the…
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
🔧Part of the DBA-Tools Project, copy/paste SQL Server scripts and health checks. There is no NOW() in SQL Server. Bring the habit over from MySQL or PostgreSQL and you get this: Msg 195 · Level 15 · State 10 ‘NOW’ is not a recognized built-in function name. TODAY() fails the same way (SQL Server 2025…
Written by
- Backups & Recovery (18)
- DBA Scripts (154)
- High Availability (HA) (13)
- Installation & Configuration (59)
- Maintenance (25)
- Migration & Upgrades (14)
- Monitoring (9)
- Performance Tuning (37)
- Security (Encryption & Permissions) (25)
- Storage & Capacity (17)
- T-SQL Fundamentals (16)
- Troubleshooting (105)
- Wait Types (236)