336,528 questions
Tooling
0
votes
1
replies
19
views
SQL Server query tuning: counting distinct matching rows across tables
I’m querying two large tables containing property transactions for 2024 and 2025. I need to count how many distinct properties (defined by county, PAON, street, city) appear in both tables, grouped by ...
-1
votes
0
answers
69
views
sp_send_dbmail runs into "Failed to initialize sqlcmd library with error number -2147417850. "
I was tasked with debugging a legacy system issue at work. A lot of our stored procedures send emails via sp_send_dbmail using the @query parameter to attach data.
However, in our Production ...
-1
votes
1
answer
80
views
SQL Server Error 1785: Introducing FOREIGN KEY constraint may cause multiple cascade paths [duplicate]
Using SQL Server I am trying to create a foreign key constraint:
Msg 1785, Level 16, State 0 Introducing FOREIGN KEY constraint 'FK_Staff_Subject_XRef_Batch' on table 'Staff_Subject_XRef' may cause ...
Best practices
0
votes
1
replies
41
views
SQL Server ON VPS With Multi-Tenant, Multi Db Architecture
Need help on a scalable cheap solution - I'm building an Access Db to run with a SQL Server back-end hosted on a VPS. I am trying to decide on the architecture to use. When I say multi-tenant I mean I ...
3
votes
4
answers
109
views
Calculate the percentage of ids with at least one record in a given group from a different table
I have three tables in a SQL Server 2019 database. A Users table with a list of user IDs, a WebApps table with a list of applications, and WepAppAuditLogs with a log of when users accessed a specific ...
1
vote
0
answers
63
views
How to fix SQLCMD variable DatabaseName not being excluded from schema compare in VS Code or Rider
When I run a schema compare in Rider in the new SDK-style .sqlproj format where the [$(DatabaseName)] value is in the *.sql code and the resolved database name is in the database side, it still ...
3
votes
2
answers
159
views
Return data between certain Hour values
I am trying to determine if it's possible to query for data between two defined HOUR values from a DateTime value, instead of writing out each DateTime iteration. This need is to find matching values ...
1
vote
2
answers
157
views
XML format from SQL data table
I need to build the following XML data structure. I get the XML structure that I need but I am missing the student tag.
<users>
<user>
<id>123</id>
<name&...
0
votes
0
answers
78
views
SSMS Creating Keyboard Shortcut for Edit.Comment works, but Edit.Uncomment does not with same config
CTRL+G works:
CTRL+B doesn't work:
I've created a custom keyboard shortcut for Edit.Comment that works using CTRL+G. I used the same configuration for Edit.Uncomment using CTRL+B which is not ...
Advice
1
vote
9
replies
110
views
Does flipping from/to dates within date index make it more selective for SQL Server
In one of my projects I have an entity with startDate (from) and expiryDate (to):
@Entity
public class BlacklistedItem {
//...
@Column(nullable = false)
private LocalDateTime startDate;
@...
Tooling
0
votes
7
replies
107
views
How to unit test SQL Server User-Defined Table Types against C# classes to ensure property order and compatibility?
I'm working on a .NET 8 application that uses SQL Server User-Defined Table Types (UDTT) to pass data to stored procedures. I have a situation where I need to ensure that my C# classes remain ...
0
votes
2
answers
102
views
Update query used the wrong table in the from statement
I accidently ran an incorrect and incomplete query on production as shown in the following.
#TempDiff is a temp table with 2 columns as shown below. There are one or many [Pallet Contents] for each ...
Best practices
0
votes
5
replies
103
views
Alter a SQL Server table column size in production
What is the best way to alter a production SQL Server 18 table's column size, varchar(n +1).
My understanding would be the following:
Shut the website down to stop the transaction from coming in.
...
0
votes
0
answers
84
views
Error when creating EDMX from LocalDB .mdf in Visual Studio 2022
I am using Visual Studio 2022 and trying to work with internal .mdf databases (LocalDB) for testing purposes in an ASP.NET Web Forms project using Entity Framework (EDMX).
Creating the database itself ...
0
votes
0
answers
21
views
Last backup, last copy, last restore are null in log shipping throgh view report log shipping [migrated]
I have made problem during configure log shipping on SQL Server 2019 standard version by missing last backup, last copies, last restore select not found on msdb.
I have been using user AD all machine ...