270 questions with SQL Server | SQL Server Transact-SQL tags

Sort by: Updated
2 answers One of the answers was accepted by the question author.

How to create initial full backup followed by transaction logs daily?

This is related to work. I have been sending out a full-back up of a database in BAK file format (using SQL Server 2022) for a client, but now the client is asking for an initial full backup followed by transaction logs daily. How do I go about doing it…

SQL Server | SQL Server Transact-SQL
asked 2026-01-30T18:06:58.63+00:00
Justin Doh 980 Reputation points
commented 2026-02-24T22:05:46.54+00:00
Erland Sommarskog 132.6K Reputation points MVP Volunteer Moderator
2 answers One of the answers was accepted by the question author.

A Scalar UDF works consistently in SQL Server 2017, fails sporadically under 2019 and 2022.

You can try this at home! I use this udf to capture the number of cores available when my stored procedure runs in cloud. But, since I develop against my local on-prem database, I coded it to return a -1 when it's not running in the cloud. Here's the…

SQL Server | SQL Server Transact-SQL
asked 2026-02-23T22:52:16.3333333+00:00
Steve Grimes 20 Reputation points
commented 2026-02-24T14:55:33.2633333+00:00
Steve Grimes 20 Reputation points
2 answers

how to fix error 1205 on mssql 2022

Riscontro vari errori 1205 nei log e dopo alcuni di questi, si verifica l'errore 824

SQL Server | SQL Server Transact-SQL
asked 2026-02-23T19:02:26.01+00:00
Luca Benedetto 20 Reputation points
answered 2026-02-23T22:18:14.8166667+00:00
Erland Sommarskog 132.6K Reputation points MVP Volunteer Moderator
5 answers One of the answers was accepted by the question author.

Syntax error in the statement

Hi, I wrote the following query and trying to figure out the syntax error: incorrect syntax near WHERE. DECLARE @SQL NVARCHAR(MAX) SET @SQL = (SELECT 'SELECT COUNT(*) FROM rv.' + table_name, +','+ QUOTENAME((table_name) + ' as table_name ' FROM…

SQL Server | SQL Server Transact-SQL
asked 2026-02-17T18:25:30.1766667+00:00
Naomi Nosonovsky 8,901 Reputation points
answered 2026-02-19T21:44:00.48+00:00
Erland Sommarskog 132.6K Reputation points MVP Volunteer Moderator
2 answers

What is SQL error ID 8179 and how to fix it?

The customer often found NAV Server error at Event Viewer (Application log), Event ID 216, MicrosoftDynamicsNavServer$MBKNAV.  It was NavSqlException, SQL error ID 8179 (“Could not find prepared statement with handle …”).  This issue often occurs when…

SQL Server | SQL Server Transact-SQL
asked 2026-02-18T02:58:30.2366667+00:00
Chirayu Traihirun 0 Reputation points
answered 2026-02-18T22:05:17.56+00:00
Erland Sommarskog 132.6K Reputation points MVP Volunteer Moderator
2 answers

unable install sql on on pc due to power shell error

unable install sql on on pc due to power shell error

SQL Server | SQL Server Transact-SQL
asked 2026-02-08T08:45:29.2966667+00:00
pravin bhingardive 0 Reputation points
edited a comment 2026-02-18T06:34:20.31+00:00
Akhil Gajavelly 1,555 Reputation points Microsoft External Staff Moderator
2 answers One of the answers was accepted by the question author.

How can I create TRN file to capture only difference daily (between TRN files)?

I am trying to understand how Transaction Log works. This question is related to my previous post. My requirement is, instead of providing BAK file (because it is huge), I am trying to generate one TRN file daily for any change (insert, update or delete)…

SQL Server | SQL Server Transact-SQL
asked 2026-02-05T20:07:21.91+00:00
Justin Doh 980 Reputation points
accepted 2026-02-12T18:03:29.3766667+00:00
Justin Doh 980 Reputation points
2 answers

sqlcmd to backup on one server and write to another

I have a sql agent job that runs a CmdExec step on server 'Destination'. It executes a full backup on server 'Source' and needs to write the backup to server 'Destination'. This works perfectly when the server names are hard coded. However, both the…

SQL Server | SQL Server Transact-SQL
asked 2026-02-04T23:00:41.0833333+00:00
bukkybu 386 Reputation points
recommended 2026-02-05T22:40:12.2866667+00:00
Erland Sommarskog 132.6K Reputation points MVP Volunteer Moderator
3 answers One of the answers was accepted by the question author.

Dose SQL Server works on Snapdragon Arm Laptop

Dose SQL Server works on Snapdragon Arm based Laptop. if yes how to run on arm based Snapdragon Laptop

SQL Server | SQL Server Transact-SQL
asked 2026-01-18T07:52:19.76+00:00
Mudassir Ahmed 100 Reputation points
accepted 2026-02-02T10:00:00.6033333+00:00
Mudassir Ahmed 100 Reputation points
1 answer

SQL error -An expression of non-boolean type specified in a context where a condition is expected

Thanks in advance for any help folks can offer. I've been pulling my hair our all day yesterday trying to figure out how to fix this. I received the error below after I added 3 new lines (line 60, 61 and 62). The original code without these 3 new lines…

SQL Server | SQL Server Transact-SQL
asked 2026-01-26T18:29:09.99+00:00
DW 0 Reputation points
commented 2026-01-29T21:46:48.2633333+00:00
D Weeman 0 Reputation points
2 answers One of the answers was accepted by the question author.

Reinitializing the replication caused the deletion of database

I’m running a pull subscription using transactional replication between two databases, where the Publisher and Distributor are the same server. We removed the permissions for the account originally used for the replication job and replaced it with a new…

SQL Server | SQL Server Transact-SQL
asked 2026-01-26T11:52:11.7366667+00:00
Shreyams Kumar 20 Reputation points
accepted 2026-01-29T06:16:07.97+00:00
Shreyams Kumar 20 Reputation points
2 answers

Joins vs Functions and Performance

It is axiomatic that joining to another table from your primary table to retrieve data, using primary keys, provides better performance than using a function. At least that's what I know from the last time I cared about it years ago. It's time to care…

SQL Server | SQL Server Transact-SQL
asked 2025-07-03T19:12:57.03+00:00
Don Thompson 0 Reputation points
recommended 2026-01-23T04:43:05.15+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
2 answers

Alternative manner to implement an hierarchy without using recursive CTEs

Hi, I'm searching an alternative manner to implement an hierarchy in T-SQL without using recursive CTEs. Actually, a MS Fabric warehouse doesn't support a such useful feature and I need to use recursive CTEs in some scenarios. Any suggests to me, please?…

SQL Server | SQL Server Transact-SQL
asked 2025-12-16T06:31:25.8+00:00
pmscorca 1,052 Reputation points
recommended 2026-01-22T17:55:43.51+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
1 answer

Recompile Command Performance Effect

We use .net core Ef .netcore version 8.0. We use an interseptor to manipulete each EF s sql commandS. This interceptor adds OPTION(RECOMPILE) to each sql query. Could you please tell me it is neccessary to use this command.

SQL Server | SQL Server Transact-SQL
asked 2025-11-30T07:44:45.0966667+00:00
Hakan Çakmak (Udepa) 0 Reputation points
recommended 2026-01-22T13:28:37.5266667+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
2 answers

Tools for SQL Query Tuning

Hi Expert, What is tool for tuning the SQL Query? I need to checking the query that take long time in running thanks for all valued information warm regards, Urbel

SQL Server | SQL Server Transact-SQL
asked 2025-11-13T03:46:44.3733333+00:00
Urbel 400 Reputation points
recommended 2026-01-22T13:24:40.7133333+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
2 answers

DBCC TRACEOFF 3604

Good afternoon SQL 2022 Standard I would like to better understand: DBCC TRACEOFF 3604 DBCC TRACEON 3604 How to use it? How to activate it? How and when should it normally be used? Thank you Urantia

SQL Server | SQL Server Transact-SQL
asked 2025-11-18T14:52:31.8666667+00:00
MadUrantia 175 Reputation points
commented 2026-01-22T06:49:21.9666667+00:00
Akhil Gajavelly 1,555 Reputation points Microsoft External Staff Moderator
2 answers

SQL Server Database Engine error during insert/update sequence in employee audit table

I was running a SQL Server test for an internal employee-audit scenario. The script creates two tables, inserts a few rows and performs joins/updates. Expected: All inserts and updates should complete successfully. Observed: Several statements fail…

SQL Server | SQL Server Transact-SQL
asked 2025-10-23T12:44:06.4233333+00:00
aditi sharma 75 Reputation points
recommended 2026-01-21T08:17:18.3233333+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
3 answers

Select most recent data per record from multiple tables

I am trying to get the latest data for a record from multiple tables. The issue I am running into is that the data on each table could have been modified at different times and each table may contain multiple rows per record. I am currently using row…

SQL Server | SQL Server Transact-SQL
asked 2025-12-10T15:59:27.8+00:00
JamesHarsh-1587 0 Reputation points
recommended 2026-01-19T17:33:48.6166667+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
1 answer

The audit for this user shows success, but when using SSMS, the error that is received is 18456 and he cannot sign in

We are using integrated security. All other users have no problem getting to this database. One user, gets and 18456 error. The user is part of the SQL Contributor Group. The activity logs for login shows successful login in SQL server through AD,…

SQL Server | SQL Server Transact-SQL
asked 2025-11-18T17:49:45.6+00:00
Patrick Dengler 0 Reputation points
recommended 2026-01-19T12:29:08.15+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator
1 answer

Raiserror doesn't output messages

Hi everybody, I have a strange problem. I have a long procedure which has 2 places that send notes for other procedure. This procedure outputs NULL by this line of code: DECLARE @message VARCHAR(200) = ' Notes is ' + ISNULL(@notes, 'NULL') RAISERROR…

SQL Server | SQL Server Transact-SQL
asked 2025-11-03T13:53:02.7566667+00:00
Naomi Nosonovsky 8,901 Reputation points
recommended 2026-01-19T12:23:35.45+00:00
Madhavi Taniparthi 0 Reputation points Microsoft External Staff Moderator