tsql

when/what locks are hold/released in READ COMMITTED isolation level

主宰稳场 提交于 2020-02-17 23:03:34
问题 I am trying to understand isolation/locks in SQL Server. I have following scenario in READ COMMITTED isolation level(Default) We have a table. create table Transactions(Tid int,amt int) with some records insert into Transactions values(1, 100) insert into Transactions values(2, -50) insert into Transactions values(3, 100) insert into Transactions values(4, -100) insert into Transactions values(5, 200) Now from msdn i understood When a select is fired shared lock is taken so no other

when/what locks are hold/released in READ COMMITTED isolation level

末鹿安然 提交于 2020-02-17 22:56:29
问题 I am trying to understand isolation/locks in SQL Server. I have following scenario in READ COMMITTED isolation level(Default) We have a table. create table Transactions(Tid int,amt int) with some records insert into Transactions values(1, 100) insert into Transactions values(2, -50) insert into Transactions values(3, 100) insert into Transactions values(4, -100) insert into Transactions values(5, 200) Now from msdn i understood When a select is fired shared lock is taken so no other

Strange TSQL behavior with COALESCE when using Order By [duplicate]

怎甘沉沦 提交于 2020-02-16 05:21:06
问题 This question already has answers here : nvarchar concatenation / index / nvarchar(max) inexplicable behavior (2 answers) Closed 4 years ago . I'm having some very strange behavior with coalesce. When I don't specify a return amount (TOP (50)) I'm only getting a single last result, but if I remove the "Order By" it works... Examples below DECLARE @result varchar(MAX) SELECT @result = COALESCE(@result + ',', '') + [Title] FROM Episodes WHERE [SeriesID] = '1480684' AND [Season] = '1' Order by

Recursive CTE Concept Confusion

倖福魔咒の 提交于 2020-02-16 05:18:40
问题 I am trying to understand the concepts of using CTE in my SQL code. I have gone through a number of online posts explaining the concept but I cannot grasp how it iterates to present the hierarchical data. One of the widely used examples to explain the R-CTE is the Employee and ManagerID Example as below: USE AdventureWorks GO WITH Emp_CTE AS ( SELECT EmployeeID, ContactID, LoginID, ManagerID, Title, BirthDate FROM HumanResources.Employee WHERE ManagerID IS NULL UNION ALL SELECT e.EmployeeID,

Recursive CTE Concept Confusion

别说谁变了你拦得住时间么 提交于 2020-02-16 05:18:29
问题 I am trying to understand the concepts of using CTE in my SQL code. I have gone through a number of online posts explaining the concept but I cannot grasp how it iterates to present the hierarchical data. One of the widely used examples to explain the R-CTE is the Employee and ManagerID Example as below: USE AdventureWorks GO WITH Emp_CTE AS ( SELECT EmployeeID, ContactID, LoginID, ManagerID, Title, BirthDate FROM HumanResources.Employee WHERE ManagerID IS NULL UNION ALL SELECT e.EmployeeID,

Strange TSQL behavior with COALESCE when using Order By [duplicate]

[亡魂溺海] 提交于 2020-02-16 05:15:43
问题 This question already has answers here : nvarchar concatenation / index / nvarchar(max) inexplicable behavior (2 answers) Closed 4 years ago . I'm having some very strange behavior with coalesce. When I don't specify a return amount (TOP (50)) I'm only getting a single last result, but if I remove the "Order By" it works... Examples below DECLARE @result varchar(MAX) SELECT @result = COALESCE(@result + ',', '') + [Title] FROM Episodes WHERE [SeriesID] = '1480684' AND [Season] = '1' Order by

Using SQl Server CE; Possible to Insert Only If Not Exists?

坚强是说给别人听的谎言 提交于 2020-02-15 04:21:14
问题 I'm trying to verify a simple 1 field table to determine if a record exists before inserting a duplicate. if not exists (select * from url where url = ...) insert into url... Can someone Help? 回答1: Your code example will run in the full version of SQL, or you could rearrange to the following: insert into url select 'myvalue' where not exists (select * from url where url = 'myvalue') 回答2: You might want to read this thread. performing-insert-or-update-upsert-on-sql-server-compact-edition In a

Using SQl Server CE; Possible to Insert Only If Not Exists?

拈花ヽ惹草 提交于 2020-02-15 04:20:49
问题 I'm trying to verify a simple 1 field table to determine if a record exists before inserting a duplicate. if not exists (select * from url where url = ...) insert into url... Can someone Help? 回答1: Your code example will run in the full version of SQL, or you could rearrange to the following: insert into url select 'myvalue' where not exists (select * from url where url = 'myvalue') 回答2: You might want to read this thread. performing-insert-or-update-upsert-on-sql-server-compact-edition In a

How to get the highest value in a row together with the column name

谁说胖子不能爱 提交于 2020-02-14 02:26:14
问题 I have a table with 10 columns, eight of them are columns with dates. My desired outcome is to get max date for each row (what I have already accomplished) but I would also like to get the name of the columns, which this max dates come from. SELECT s.sp_id ,s.sp_numer ,( SELECT MAX(Data_przedawnienia_update) FROM ( VALUES (Data_przedawnienia_Postanowienie_o_umorzeniu_egzekucji) ,(Data_przedawnienia_Egzekucja_w_toku) ,(Data_przedawnienia_Nakaz_zaplaty_z_klauzula) ,(Data_przedawnienia_Nakaz

Delete duplicates from large dataset (>100Mio rows)

心不动则不痛 提交于 2020-02-13 03:02:31
问题 I know that this topic came up many times before here but none of the suggested solutions worked for my dataset because my laptop stopped calculating due to memory issues or full storage. My table looks like the following and has 108 Mio rows: Col1 |Col2 | Col3 |Col4 |SICComb | NameComb Case New |3523 | Alexander |6799 |67993523| AlexanderCase New Case New |3523 | Undisclosed |6799 |67993523| Case NewUndisclosed Undisclosed|6799 | Case New |3523 |67993523| Case NewUndisclosed Case New |3523 |