sql-server-2008-r2

History of commands on SQL Server

别说谁变了你拦得住时间么 提交于 2019-12-06 10:00:39
问题 This query gives me the history of commands executed on SQL Server: Select * From ( SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest ) x When I added Where x.Query LIKE '%Insert%' I get bad results (I think that this is because of the cross join): Select * From ( SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm

Dump list of full paths of parent/child type records in SQL Server 2008 R2

ぃ、小莉子 提交于 2019-12-06 09:27:19
I need to retrieve the list of full paths of groups (folders) stored in the database as such: select * from groups; group_id parent_group_id name -------- --------------- ------------------------------- 1 NULL Root 2 1 Folder1 3 2 Folder2 4 3 Folder3 There is no limit to the possible depth of groups (could be nested almost indefinitely), so I don't know in advance how many levels I could have. I would like to be able to get the following results from a query and load that into a table that I could use to join full paths with group_ids in other queries: group_id path -------- ------------------

Creating Users on secondary server in log shipping

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:24:46
问题 I have a production Server say ServerA I have setup log shipping to ServerB which is left in read-only mode. The purpose of this log shipping is to lower the load on production server for some expensive queries (painful reports). Now if I have to create some logins using our domain accounts. I cannot do this because the secondary database is in standby mode . I thought if I create these logins on Primary server it will be copied over to secondary server then the logs are restored there but

Copy missing rows from one table to another in sql server with stored procedure

房东的猫 提交于 2019-12-06 08:52:40
I have to tables in different databases (on the same server) that are identical. I need to transfer the data rows from the left database table to the right database table, but I only want to transfer the rows that aren't in the right database table already. Is there a neat way of doing this? Im using SQL Server 2008 R2 Assuming that you can uniquelly identify a row with column id : insert into databasename..tablename select * from datababasename2..tablename2 where id not in (select id from databasename..tablename) 来源: https://stackoverflow.com/questions/10885129/copy-missing-rows-from-one

Sql Server row size limit and table design

柔情痞子 提交于 2019-12-06 08:49:17
I have this query on SQL Server 2008 CREATE TABLE MediaLibrary ( MediaId bigint NOT NULL IDENTITY (1, 1), MediaTypeId smallint NOT NULL, ImageNameByUser nchar(100) NULL, GeneratedName uniqueidentifier NOT NULL, UploadedByUserId uniqueidentifier NOT NULL, UploadedDate date NOT NULL, ProfilePhoto bit NOT NULL, PublicPhoto bit NOT NULL, AppointmentId bigint NULL, OriginalImage nchar(1000) NULL, ThumbImage nchar(1000) NULL, MediumImage nchar(1000) NULL, LargeImage nchar(1000) NULL, UrlThumb nchar(1000) NULL, UrlMedium nchar(1000) NULL, UrlLarge nchar(1000) NULL, InactiveReasonId smallint NULL,

sql error not thrown back to caller

五迷三道 提交于 2019-12-06 08:13:53
问题 I am new to this forum but please bear with me. I have a c# Windows form which has two checkboxes on it One is called chkThrowError and the other is called chkDivideError, both are unchecked. These controls are purely there to control execution of a stored procedure. I have a command Button with the following Code: private void cmdError_Click(object sender, EventArgs e) { int ThrowError = 0; int DividByZero = 0; if (chkThrowError.Checked) { ThrowError = 1; } if (chkDivideError.Checked) {

How to optimise the 'XQuery' SQL

青春壹個敷衍的年華 提交于 2019-12-06 07:48:17
问题 I have an XML hierarchy like this in an XML type column of a table with 10,000 records- <Root> <Elem1> <Parent1> <Separator> <Child1/> </Separator> </Parent1> </Elem1> </Root> I have a query like this - DECLARE @Root VARCHAR(50) DECLARE @Entity VARCHAR(50) DECLARE @ParentNode VARCHAR(50) DECLARE @Separator VARCHAR(50) DECLARE @ChildNode VARCHAR(50) SET @Root = 'Root' SET @Entity = 'Elem1' SET @ParentNode = 'Parent1' SET @Separator = 'separator' SET @ChildNode = 'Child1' select Parent.P.value(

Table hiding in SQL Server database?

时光毁灭记忆、已成空白 提交于 2019-12-06 07:40:46
问题 I am transferring data into a table all of sudden I went throgh a crazy problem I have never seen in my career. Msg 208, Level 16, State 1, Line 1 Invalid object name 'dbo.Table_Report'. Then I tried to create a table with same name and again I got fallowing error Msg 2714, Level 16, State 6, Line 2 There is already an object named 'Table_Report' in the database. What went wrong I need to send data in to table asap but I am unable to do that at least I can't delete the table Cannot drop the

SQL query to show change history of data

只谈情不闲聊 提交于 2019-12-06 07:38:12
问题 I have a table in a SQL Server database which stores historical data on daily basis. The structure is shown below: UploadDate TypeID Value1 Value2 ------------------------------------------- 2012-01-08 1 NEG 1998-02-05 2012-01-08 2 NEG 1999-02-09 2012-01-08 3 STABLE 1997-02-06 2012-02-08 1 NEG 1998-02-05 2012-02-08 2 NEG 1999-02-09 2012-03-08 1 POS 2012-03-08 2012-03-08 2 STABLE 2012-01-08 As you can see above for the TypeID 1 & 2, Value1 and Value2 has changed on 2012-03-08 My requirement is

How to use T-SQL MERGE in this case?

不羁岁月 提交于 2019-12-06 07:26:36
问题 I'm new to T-SQL command MERGE so I found a place in my SQL logic where I can use it and want to test it but can't figure out how exactly should I use it: IF (EXISTS (SELECT 1 FROM commissions_history WHERE request = @requestID)) UPDATE commissions_history SET amount = @amount WHERE request = @requestID ELSE INSERT INTO commissions_history (amount) VALUES @amount) Please suggest the proper usage. Thanks! 回答1: Did you look in the help? Here's a simple example: MERGE dbo.commissions_history AS