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

Sort by: Updated
2 answers

What causes these randomly-generated temporary table names?

In a stored procedure I create a temporary table like so: begin transaction drop table if exists #foo; create table #foo (id varchar(5) collate database_default not null); <insert some data> commit; save transaction temp_table; This works fine,…

SQL Server | SQL Server Transact-SQL
asked 2026-01-06T22:19:44.3566667+00:00
Dan Blum 0 Reputation points
answered 2026-01-06T22:58:37.55+00:00
Erland Sommarskog 130.6K Reputation points MVP Volunteer Moderator
1 answer One of the answers was accepted by the question author.

Known issue? Insert into temp table sometimes throws 8152 instead of 2628

Our system frequently needs to create temporary tables in order to pass data from Java to stored procedures. Since we are using SQL Server 2022, I would expect that when inserting a too-large value into a column we would get exception 2628 with the…

SQL Server | SQL Server Transact-SQL
asked 2026-01-06T19:01:14.06+00:00
Dan Blum 0 Reputation points
commented 2026-01-06T20:46:35.7833333+00:00
Dan Blum 0 Reputation points
2 answers

Failed to create backup file in SQL Server

Hello, I'm having trouble with SQL Server backups and have a question. I translated this from Japanese, so the wording might be a bit awkward. [Environment] SQL Server 2019 running on a Hyper-V virtual environment on Windows Server 2016 [Issue] During…

SQL Server | SQL Server Transact-SQL
asked 2025-12-26T01:35:10.4033333+00:00
UTAMARO 0 Reputation points
commented 2026-01-06T09:57:08.3866667+00:00
Erland Sommarskog 130.6K Reputation points MVP Volunteer Moderator
1 answer

Identity Column jumps massively from 168712 to 9999993

I have table with identity column id. There was massive jump from id 168712 to 9999993. It has happened twice in different servers. Its not identity cache/transaction rollback/manual insert/ reseed. Why its happening. Please guide me on this.

SQL Server | SQL Server Transact-SQL
asked 2025-10-17T16:06:46.38+00:00
Perumal, Gowthami 5 Reputation points
commented 2026-01-02T10:32:41.6466667+00:00
Akhil Gajavelly 1,110 Reputation points Microsoft External Staff Moderator
1 answer

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
commented 2025-12-24T08:29:35.46+00:00
Shruti Dhruv 560 Reputation points Microsoft External Staff Moderator
2 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
commented 2025-12-22T08:37:53.4366667+00:00
Lakshmi Narayana Garikapati 740 Reputation points Microsoft External Staff Moderator
2 answers One of the answers was accepted by the question author.

Question about "BACKUP Database" statement

This question is very closely related to my previous post, but I am posting here again because this is little bit time sensitive. Currently, I have pipeline completed where I use T-SQL statement as below to create a BAK file daily in Prem SQL: BACKUP…

SQL Server | SQL Server Transact-SQL
asked 2025-12-17T21:34:49.2933333+00:00
Justin Doh 920 Reputation points
commented 2025-12-17T22:40:14.5233333+00:00
Erland Sommarskog 130.6K Reputation points MVP Volunteer Moderator
1 answer One of the answers was accepted by the question author.

Descrepancy between SalesLT.SalesOrderDetail and SalesLT.SalesOrderHeader?

I deployed a new AdventureWorks LT. When I query: select * from SalesLT.SalesOrderDetail where salesorderID = 71774 there's 2 rows: SalesOrderDetailID's 110562 and 110563. They both have a linetotal of 356.898000 so when I query: select sum(LineTotal)…

SQL Server | SQL Server Transact-SQL
asked 2025-12-10T14:31:19.0566667+00:00
Jasper Versteegh 45 Reputation points
commented 2025-12-15T14:27:30.7633333+00:00
Jasper Versteegh 45 Reputation points
2 answers One of the answers was accepted by the question author.

Sql 2025 T-SQL Job

SQL 2025 Std running in a Windows server 2022 Std A job with a T-SQL task (which calls a stored procedure) ran well weekly for almost a month, at a specific time of day For various reasons, I had to change it so that it would run at a different time of…

SQL Server | SQL Server Transact-SQL
asked 2025-11-09T17:54:49.8566667+00:00
Delmira Oliveira 160 Reputation points
accepted 2025-12-14T17:26:02.8233333+00:00
Delmira Oliveira 160 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
commented 2025-12-12T07:45:50.4966667+00:00
Dinesh Yadlapalli 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
commented 2025-12-09T11:51:24.3466667+00:00
Shruti Dhruv 560 Reputation points Microsoft External Staff Moderator
1 answer

sql server

how can i get a sql certificate from microsoft what all things do I need to do and how please explain

SQL Server | SQL Server Transact-SQL
asked 2025-11-28T12:41:56.46+00:00
Jivesh Pandey 0 Reputation points
answered 2025-12-08T12:34:47.8433333+00:00
Kimci Smith 0 Reputation points
3 answers

Using IsNull with different data types in SQL SERVER

Hi Team, I am working on on premises SQL Server. I have a requirement where I need to apply left outer join between 2 tables and use IsNull to show default data when columns are having null. Under ISNULL, if a column is null what shall i put for below…

SQL Server | SQL Server Transact-SQL
asked 2025-06-06T18:06:46.15+00:00
Salil Singh 60 Reputation points
commented 2025-12-05T05:48:58.35+00:00
Venkata Ramanamma Uppu (Quadrant Technologies LLC) 0 Reputation points Microsoft External Staff
1 answer One of the answers was accepted by the question author.

Assigning large text block to nvarchar(max) SOMETIMEs truncates at 4000 bytes

I have a really large dynamic sql query (19,000+ in length) that is assigned to @SQLText nvarchar(max). Everything was working. Made some minor changes and then @SQLText variable only contained 4000 characters, truncating the rest of the query text.…

SQL Server | SQL Server Transact-SQL
asked 2025-07-14T15:30:33.5+00:00
Grossnickle, Brenda 160 Reputation points
accepted 2025-12-04T04:06:07.54+00:00
Grossnickle, Brenda 160 Reputation points
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
edited a comment 2025-12-02T12:24:49.8366667+00:00
Shruti Dhruv 560 Reputation points Microsoft External Staff Moderator
0 answers

SQL server 2022 job fails

Hello SQL Server 2022 16.0.4212.1 Installed in a windows server 2025 DC. SQLSERVERAGENT starts with NT Service\SQLSERVERAGENT I have some jobs that runs at the scheduled times. But one no. Failure: "Job failed. The job was invoked by Schedule 9…

SQL Server | SQL Server Transact-SQL
asked 2025-09-11T07:43:40.6466667+00:00
Delmira Oliveira 160 Reputation points
commented 2025-11-30T20:10:22.81+00:00
MadUrantia 85 Reputation points
1 answer

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
RASWADI 340 Reputation points
commented 2025-11-27T11:04:34.8933333+00:00
Lakshmi Narayana Garikapati 740 Reputation points Microsoft External Staff Moderator
2 answers

Latest security update has caused SS debugger to fail... 2008 r2 windows 10 - Windows Firewall

Getting: The WIndows Firewall on this machine is currently blocking remote debugging. RD requires... TCP Port 135... UDP 4500/ 500 be unblocked. Can't Cancel, Unlock for local or Unlock for Computer. Trying to "Debug>Start Debugging".

SQL Server | SQL Server Transact-SQL
asked 2025-07-12T01:50:50.6933333+00:00
M Douglas Martin 0 Reputation points
commented 2025-11-26T12:22:32.1+00:00
Venkata Ramanamma Uppu (Quadrant Technologies LLC) 0 Reputation points Microsoft External Staff
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,881 Reputation points
answered 2025-11-25T12:36:51.2033333+00:00
Naomi Nosonovsky 8,881 Reputation points
1 answer

I created connections via mssql extension in vs code and now when I click on mssql, I don't see them.

I saved database connections in via mssql extension in vs code and now when I click on mssql, I don't see them. All I see when I click on the mssql icon is this.

SQL Server | SQL Server Transact-SQL
asked 2025-07-25T20:19:25.4233333+00:00
Amy Petrone 0 Reputation points
commented 2025-11-25T05:17:42.4466667+00:00
Nithin Krishna Madadi 0 Reputation points Microsoft External Staff Moderator