sql-server-2005

Having TRANSACTION In All Queries

喜你入骨 提交于 2019-12-17 20:19:54
问题 Do you think always having a transaction around the SQL statements in a stored procedure is a good practice? I'm just about to optimize this legacy application in my company, and one thing I found is that every stored procedure has BEGIN TRANSACTION . Even a procedure with a single select or update statement has one. I thought it would be nice to have BEGIN TRANSACTION if performing multiple actions, but not just one action. I may be wrong, which is why I need someone else to advise me.

SQL Server error handling: exceptions and the database-client contract

六眼飞鱼酱① 提交于 2019-12-17 20:15:34
问题 We’re a team of SQL Servers database developers. Our clients are a mixed bag of C#/ASP.NET, C# and Java web services, Java/Unix services and some Excel. Our client developers only use stored procedures that we provide and we expect that (where sensible, of course) they treat them like web service methods. Some our client developers don’t like SQL exceptions. They understand them in their languages but they don’t appreciate that the SQL is limited in how we can communicate issues. I don’t just

SQL Server 2008 compatibility with SQL Server 2005

拟墨画扇 提交于 2019-12-17 19:48:09
问题 What is the best way to use SQL Server 2008 as a development database, but ensure that the database is compatible with SQL Server 2005? 回答1: This can be done via SQL Enterprise Manager or like this: ALTER DATABASE <database> SET COMPATIBILITY_LEVEL = { 80 | 90 | 100 } Use 90 for 2005 compatibility. This replaces the functionality used for previous releases, the stored procedure sp_dbcmptlevel . 回答2: You can set the database compatibility level, but there is no guarantee that this will cover

sql server 'in' or 'or' - which is fastest

自闭症网瘾萝莉.ら 提交于 2019-12-17 19:39:14
问题 Ok, so I have a query: select distinct(a) from mytable where b in (0,3) What is going to be faster, the above or select distinct(a) from mytable where b = 0 or b = 3 Is there a general rule? Thanks 回答1: Both IN and OR will do a query for b = 0 followed by one for b = 3 , and then do a merge join on the two result sets, and finally filter out any duplicates. With IN , duplicates doesn't really make sense, because b can't both be 0 and 3 , but the fact is that IN will be converted to b = 0 OR b

Passing multiple values for one SQL parameter

眉间皱痕 提交于 2019-12-17 19:30:48
问题 I have a CheckBoxList where users can select multiple items from the list. I then need to be able to pass these values to my Stored Procedure so they can be used in a WHERE condition like: WHERE ID IN (1,2,3) I tried doing this so that its a nvarchar parameter and i pass the string 1,2,3 with: WHERE ID IN (@IDs) But this returned the following error: Conversion failed when converting the nvarchar value '1,2,3' to data type int Any help would be much appreciated! 回答1: There's a few ways of

How do i transform rows into columns in sql server 2005

久未见 提交于 2019-12-17 19:10:17
问题 There is a question here in stackoverflow with the same title but that is not what I am looking for. I have a table like the one below Name | Count ---------------- Chery | 257 Drew | 1500 Morgon | 13 Kath | 500 Kirk | 200 Matt | 76 I need to trasform this result set into something like this Chery | Drew | Morgon | Kath | Kirk | Matt ------------------------------------------- 257 1500 13 500 200 76 How do i acheive this using sql server 2005? 回答1: There are similar questions here,here

How to convert int to date in SQL Server 2008

拟墨画扇 提交于 2019-12-17 18:55:53
问题 I am using MS SQL Server 2008, and in a table I have column idate as date but in the integer format. But in the query I want that in the date format. Is it possible to convert integer date into proper datetime format? 回答1: You can't convert an integer value straight to a date but you can first it to a datetime then to a date type select cast(40835 as datetime) and then convert to a date (SQL 2008) select cast(cast(40835 as datetime) as date) cheers 回答2: You have to first convert it into

How do I ensure Linq to Sql doesn't override or violate non-nullable DB default values?

心已入冬 提交于 2019-12-17 18:51:43
问题 I have an SQL Server DB with a table with these fields: A bit with the default value 1, NOT NULL . A smalldatetime with the default value gettime() , NOT NULL . An int with no default value, IDENTITY , NOT NULL . When I generate Linq to SQL for this table, the following happens: The bit is given no special treatment. The smalldatetime is given no special treatment. The int is marked as IsDbGenerated . This means that when I make inserts using Linq to SQL, the following will happen: The bit

Performance of COUNT SQL function

风格不统一 提交于 2019-12-17 18:42:06
问题 I have two choices when writing an SQL statement with the COUNT function. SELECT COUNT(*) FROM <table_name> SELECT COUNT(some_column_name) FROM <table_name> In terms of performance, what is the best SQL statement? Can I obtain some performance gain by using option 1? 回答1: Performance should not matter because they do 2 different aggregates COUNT(*) is all rows, including NULLs COUNT(some_column_name) , excludes NULL in " some_column_name " See the "Count(*) vs Count(1)" question for more 回答2:

Login failed. Login failed for user 'NT AUTHORITY\SYSTEM'

放肆的年华 提交于 2019-12-17 18:37:10
问题 I have created a windows service & my service is dependent on the SQL server service. First, SQL started and then my service started when starting PC or restarting PC. This works fine but the issue is database file can not be read by the Windows service, throwing the exception "Cannot open user default database. Login failed.Login failed for user 'NT AUTHORITY\SYSTEM' " when i am trying to read the database. If I start the computer & login then it can not read the database, but if i have