What does this statement do @@RowCount > 0

Viewed 7226

Taken from the book : "Julia Lerman - Programming Entity Framework "

when creating a new entity in EF :

   var contact = Contact.CreateContact(0, "Camey", "Combs", DateTime.Now, DateTime.Now);
   context.Contacts.AddObject(contact);
   context.SaveChanges(); 

The generated sql :

   exec sp_executesql N'insert [dbo].[Contact]([FirstName], [LastName], [Title],
   [AddDate], [ModifiedDate])
   values (@0, @1, null, @2, @3)
   select [ContactID]
   from [dbo].[Contact]
   where @@ROWCOUNT > 0 and [ContactID] = scope_identity()',
   N'@0 nvarchar(50),@1 nvarchar(50),@2 datetime2(7),@3 datetime2(7)',
   @0=N'Camey',@1=N'Combs',@2='2009-08-30 09:27:31.7449098',
   @3='2009-11-30 09:27:31.7449098'

What is @@RowCount > 0 used for in the where clause ?

I'm not sure of what it does according to msdn it returns the number of affected rows , so as i understand it , this is just a way the verify that the Contact record was added they could of also have written @@ROWCOUNT = 1

is this correct ?

3 Answers
Related