sql-server-2005

How to change slow parametrized inserts into fast bulk copy (even from memory)

梦想与她 提交于 2020-01-12 10:09:31
问题 I had someting like this in my code (.Net 2.0, MS SQL) SqlConnection connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=DataBase;Integrated Security=True"); connection.Open(); SqlCommand cmdInsert = connection.CreateCommand(); SqlTransaction sqlTran = connection.BeginTransaction(); cmdInsert.Transaction = sqlTran; cmdInsert.CommandText = @"INSERT INTO MyDestinationTable" + "(Year, Month, Day, Hour, ...) " + "VALUES " + "(@Year, @Month, @Day, @Hour, ...) "; cmdInsert

How to minus instead of add in a Sum() like sql function [closed]

三世轮回 提交于 2020-01-12 09:53:33
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago . I have a group by clause in a sql statement and need to use an aggregate function to minus all the values in each group instead of adding like the Sum() function. i.e. SELECT Sum(A) FROM ( SELECT 2 AS A UNION

How to check blocking queries in SQL Server

爷,独闯天下 提交于 2020-01-12 08:09:30
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

How to check blocking queries in SQL Server

末鹿安然 提交于 2020-01-12 08:09:08
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

Select Parent Record With All Children in SQL

爱⌒轻易说出口 提交于 2020-01-12 07:31:08
问题 Let's say I have two tables, "Parent" and "Child". Parent-to-Child is a many:many relationship, implemented through a standard cross-referencing table. I want to find all records of Parent that are referenced by ALL members of a given set of Child using SQL (in particular MS SQL Server's T-SQL; 2005 syntax is acceptable). For example let's say I have: List item Parent Alice Parent Bob Child Charlie references Alice, Bob Child David references Alice Child Eve references Bob My goals are: If I

Tips for improving performance of DB that is above size 40 GB (Sql Server 2005) and growing monthly by around 3GB

时光毁灭记忆、已成空白 提交于 2020-01-12 05:25:30
问题 The current DB or our project has crossed over 40 GB this month and on an average it is growing monthly by around 3 GB. Now all the tables are best normalized and proper indexing has been used. But still as the size is growing it is taking more time to fire even basic queries like 'select count(1) from table'. So can u share some more points that will help in this front. Database is Sql Server 2005. Further if we implement Partitioning wouldn't it create a overhead ? Thanks in advance. 回答1:

Tips for improving performance of DB that is above size 40 GB (Sql Server 2005) and growing monthly by around 3GB

倾然丶 夕夏残阳落幕 提交于 2020-01-12 05:25:07
问题 The current DB or our project has crossed over 40 GB this month and on an average it is growing monthly by around 3 GB. Now all the tables are best normalized and proper indexing has been used. But still as the size is growing it is taking more time to fire even basic queries like 'select count(1) from table'. So can u share some more points that will help in this front. Database is Sql Server 2005. Further if we implement Partitioning wouldn't it create a overhead ? Thanks in advance. 回答1:

Simple way to prevent a Divide By Zero error in SQL

≯℡__Kan透↙ 提交于 2020-01-12 04:44:17
问题 I have a SQL query which used to cause a Divide By Zero exception I've wrapped it in a CASE statement to stop this from happening. Is there a simpler way of doing this? Here's my code: Percentage = CASE WHEN AttTotal <> 0 THEN (ClubTotal/AttTotal) * 100 ELSE 0 END 回答1: A nicer way of doing this is to use NULLIF like this: Percentage = 100 * ClubTotal / NULLIF(AttTotal, 0) 回答2: I'm using NULLIF bit differently, because in some cases I do have to return some value. Usually I need to return 0

Get Service Account Details of the SQL Agent Service

◇◆丶佛笑我妖孽 提交于 2020-01-12 03:29:07
问题 How can I get the Service Account name for the SQL Agent service for a particular SQL Server (SQL 2005). Is it possible to get using SQL statements or WMI ? 回答1: You can use the sc.exe. To find SQL instances services: sc \\<remote computer name> query | find /i "sql" To get configuration: sc \\<remote computer name> qc <service name from listing above> 回答2: As Aaron Bertrand pointed out, you can use the undocumented xp_regread in SQL Server 2005 and SQL Server 2008, but there is a better way,

Optimizing SQL queries by removing Sort operator in Execution plan

ぐ巨炮叔叔 提交于 2020-01-12 03:13:16
问题 I’ve just started looking into optimizing my queries through indexes because SQL data is growing large and fast. I looked at how the optimizer is processing my query through the Execution plan in SSMS and noticed that a Sort operator is being used. I’ve heard that a Sort operator indicates a bad design in the query since the sort can be made prematurely through an index. So here is an example table and data similar to what I’m doing: IF OBJECT_ID('dbo.Store') IS NOT NULL DROP TABLE dbo.[Store