sql-server-2005

Find Locked Table in SQL Server

蓝咒 提交于 2019-12-17 17:27:10
问题 How can we find which table is locked in the database? Please, suggest. 回答1: You can use sp_lock (and sp_lock2 ), but in SQL Server 2005 onwards this is being deprecated in favour of querying sys.dm_tran_locks: select object_name(p.object_id) as TableName, resource_type, resource_description from sys.dm_tran_locks l join sys.partitions p on l.resource_associated_entity_id = p.hobt_id 回答2: sp_lock When reading sp_lock information, use the OBJECT_NAME( ) function to get the name of a table from

How do I check if a SQL Server text column is empty?

前提是你 提交于 2019-12-17 17:25:20
问题 I am using SQL Server 2005. I have a table with a text column and I have many rows in the table where the value of this column is not null, but it is empty. Trying to compare against '' yields this response: The data types text and varchar are incompatible in the not equal to operator. Is there a special function to determine whether the value of a text column is not null but empty? 回答1: where datalength(mytextfield)=0 回答2: ISNULL( case textcolum1 WHEN '' THEN NULL ELSE textcolum1 END

Is it necessary to use # for creating temp tables in SQL server?

心不动则不痛 提交于 2019-12-17 17:24:55
问题 Is it necessary to use # before creating a temporary table in SQL server? Example: SELECT column1, column2, someInt, someVarChar INTO ItemBack1 FROM table2 WHERE table2.ID = 7 For ItemBack1 is it necessary to use the # symbol? If not, then what is the use of # in creating temp tables? 回答1: Yes. You need to prefix the table name with "#" (hash) to create temporary tables. If you do NOT need the table later, go ahead & create it. Temporary Tables are very much like normal tables. However, it

How to implement badges?

孤者浪人 提交于 2019-12-17 17:19:46
问题 I've given some thought to implementing badges (just like the badges here on Stack Overflow) and think it would be difficult without Windows services, but I'd like to avoid that if possible. I came up with a plan to implement some examples: Audobiographer: Check if all fields in the profile is filled out. Commentor: When making a comment check if the number of comments equal 10, if so award the badge. Good Answer: When voting up check to see if vote score is 25 or higher. How could this be

Changing SQL Server named instance to default instance

你说的曾经没有我的故事 提交于 2019-12-17 16:52:32
问题 This question is in regard to instances. That I asked earlier. Is it possible to change default instance in SQL Server without uninstalling and re-installing? How do we do that if possible? If not possible why is that? Thank you for help :). 回答1: No. If you want to change the name of your instance, or make it the default instance, you have to reinstall. No way around that. 回答2: All instanses are named but only one runs as default. Remove the port from the default instance and set the port of

Changing SQL Server named instance to default instance

两盒软妹~` 提交于 2019-12-17 16:52:13
问题 This question is in regard to instances. That I asked earlier. Is it possible to change default instance in SQL Server without uninstalling and re-installing? How do we do that if possible? If not possible why is that? Thank you for help :). 回答1: No. If you want to change the name of your instance, or make it the default instance, you have to reinstall. No way around that. 回答2: All instanses are named but only one runs as default. Remove the port from the default instance and set the port of

Temporary Table Scope?

自古美人都是妖i 提交于 2019-12-17 16:46:07
问题 I am making use of temporary tables #tempTable in my stored procedure - that I make use to run my ASP.net Reports (Reporting services) I am doing something like eg. Code SELECT * INTO #tempTable FROM Contacts WHERE ContactID < 10 Then I use something like SELECT o.* FROM #tempTable t INNER JOIN Orders o ON t.ContactID =o.ContactID to return values to my reports aka results for the stored procedure I do not get rid of my #tempTable i.e. I don't do DROP TABLE #tempTable I have read that the

For autoincrement fields: MAX(ID) vs TOP 1 ID ORDER BY ID DESC

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:35:11
问题 I want to find the highest AutoIncremented value from a field. (its not being fetched after an insert where I can use @@SCOPE_IDENTITY etc) Which of these two queries would run faster or gives better performance. Id is the primary key and autoincrement field for Table1 . And this is for Sql Server 2005. SELECT MAX(Id) FROM Table1 SELECT TOP 1 Id FROM Table1 ORDER BY Id DESC [Edit] Yes in this case Id is the field on which I have defined the clustered index. If the index is ID DESC then what..

Aggregate bitwise-OR in a subquery

本小妞迷上赌 提交于 2019-12-17 16:33:47
问题 Given the following table: CREATE TABLE BitValues ( n int ) Is it possible to compute the bitwise-OR of n for all rows within a subquery ? For example, if BitValues contains these 4 rows: +---+ | n | +---+ | 1 | | 2 | | 4 | | 3 | +---+ I would expect the subquery to return 7. Is there a way to do this inline, without creating a UDF ? 回答1: WITH Bits AS ( SELECT 1 AS BitMask UNION ALL SELECT 2 UNION ALL SELECT 4 UNION ALL SELECT 8 UNION ALL SELECT 16 ) SELECT SUM(DISTINCT BitMask) FROM ( SELECT

Select “where clause” evaluation order

大城市里の小女人 提交于 2019-12-17 16:32:05
问题 In Sql Server 2005 when I have multiple parameters do I have the guarantee that the evaluation order will always be from left to right? Using an example: select a from table where c=1 and d=2 In this query if the "c=1" condition fails the "d=2" condition will never be evaluated? PS- "c" is an integer indexed column, d is a large varchar and non indexable column that requires a full table scan update I was trying to avoid performing two queries or conditional statements, I just need something