sql-server-2008-r2

How to rename database in multi-user mode

落花浮王杯 提交于 2020-01-11 17:54:46
问题 I am working on SQL SERVER 2008 & 2008 R2. How can I rename a database in multi-user mode? I am using sp_rename but it returns this error: Msg 15225, Level 11, State 1, Procedure sp_rename, Line 338 回答1: You can't rename a database while it is in use. Either wait for a maintenance window, or force the database to single user mode (which will kick everyone out): USE [master]; GO ALTER DATABASE foo SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO --EXEC sys.sp_renamedb @dbname = N'foo', @newname = N

How to rename database in multi-user mode

China☆狼群 提交于 2020-01-11 17:54:05
问题 I am working on SQL SERVER 2008 & 2008 R2. How can I rename a database in multi-user mode? I am using sp_rename but it returns this error: Msg 15225, Level 11, State 1, Procedure sp_rename, Line 338 回答1: You can't rename a database while it is in use. Either wait for a maintenance window, or force the database to single user mode (which will kick everyone out): USE [master]; GO ALTER DATABASE foo SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO --EXEC sys.sp_renamedb @dbname = N'foo', @newname = N

How can I group student scores into quintile using SQL Server 2008

混江龙づ霸主 提交于 2020-01-11 14:29:30
问题 Can anyone help me to group student scores into quintile? I think there is a feature in SQL Server 2012, but still we haven t upgraded to it as we are using 2008R2. I tried Ntile(5)` but it is not generating the desired result. I need below Quintile column Student Score Quintile ------------------------ Student1 20 1 Student2 20 1 Student3 30 2 Student4 30 2 Student5 40 2 Student6 40 2 Student7 50 3 Student8 50 3 Student9 60 3 Student10 70 4 Student11 70 4 Student12 80 4 Student13 80 4

Update a table from two comma separated parameter as input

情到浓时终转凉″ 提交于 2020-01-11 10:56:10
问题 I have a Gridview in front end where Grid have two columns : ID and Order like this: ID Order 1 1 2 2 3 3 4 4 Now user can update the order like in front end Gridview: ID Order 1 2 2 4 3 1 4 3 Now if the user click the save button the ID and order data is being sent to Stored Procedure as @sID = (1,2,3,4) and @sOrder = (2,4,1,3) Now if I want to update the order and make save I want to store it into database. Through Stored procedure how can update into the table so that the table is updated

how i can remove all NewLine from a variable in SQL Server?

烈酒焚心 提交于 2020-01-10 22:20:44
问题 how i can remove all NewLine from a variable in SQL Server? I use SQL Server 2008 R2. I need remove all NewLine in a variable in a T-Sql Command. For example : Declare @A NVarChar(500) Set @A = ' 12345 25487 154814 ' Print @A And it printed like this 12345 25487 154814 But i want get string like this 12345 25487 154814 I write this query but it not work : Set @A = Replace(@A,CHAR(13),' ') 回答1: You must use this query Declare @A NVarChar(500); Set @A = N' 12345 25487 154814 '; Set @A = Replace

Full text search installed or not

别来无恙 提交于 2020-01-10 21:19:35
问题 I have instaled SQL server 2008 R2 and when I run this SQL in SQL server management studio: SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled') I get 0 But If I run this: SELECT * FROM sys.fulltext_catalogs I get one row. I want to know If fulltext search is installed on my sql server or do I need to reinstall SQL server with advance options. Please suggest. 回答1: My answer: If FULLTEXTSERVICEPROPERTY says it's not installed, then I would install from the original media. Run through the

Full text search installed or not

放肆的年华 提交于 2020-01-10 21:18:26
问题 I have instaled SQL server 2008 R2 and when I run this SQL in SQL server management studio: SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled') I get 0 But If I run this: SELECT * FROM sys.fulltext_catalogs I get one row. I want to know If fulltext search is installed on my sql server or do I need to reinstall SQL server with advance options. Please suggest. 回答1: My answer: If FULLTEXTSERVICEPROPERTY says it's not installed, then I would install from the original media. Run through the

CTE very slow when Joined

拜拜、爱过 提交于 2020-01-10 18:43:09
问题 I have posted something similar before, but I am approaching this from a different direction now so I opened a new question. I hope this is OK. I have been working with a CTE that creates a sum of charges based on a Parent Charge. The SQL and details can be seen here: CTE Index recommendations on multiple keyed table I don't think I am missing anything on the CTE, but I am getting a problem when I use it with a big table of data (3.5 million rows). The table tblChargeShare contains some other

MERGE Query and deleting records

天涯浪子 提交于 2020-01-10 17:28:11
问题 I have a table that looks something like: AccountID, ItemID 1, 100 1, 200 2, 300 I have a proc that accepts a table value parameter which updates the Items associated with an account. We'll pass something like the following: AccountID, ItemID 3, 100 3, 200 The proc looks something like: procedure dbo.MyProc( @Items as dbo.ItemListTVP READONLY ) AS BEGIN MERGE INTO myTable as target USING @Items on (Items.AccountId = target.AccountId) AND (Items.ItemId = target.ItemId) WHEN NOT MATCHED BY

MERGE Query and deleting records

[亡魂溺海] 提交于 2020-01-10 17:27:17
问题 I have a table that looks something like: AccountID, ItemID 1, 100 1, 200 2, 300 I have a proc that accepts a table value parameter which updates the Items associated with an account. We'll pass something like the following: AccountID, ItemID 3, 100 3, 200 The proc looks something like: procedure dbo.MyProc( @Items as dbo.ItemListTVP READONLY ) AS BEGIN MERGE INTO myTable as target USING @Items on (Items.AccountId = target.AccountId) AND (Items.ItemId = target.ItemId) WHEN NOT MATCHED BY