What are the pros and cons to keeping SQL in Stored Procs versus Code [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Closed 8 years ago. Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. What are the advantages/disadvantages of keeping SQL in your C# source code or in … Read more

How to call Stored Procedure in Entity Framework 6 (Code-First)?

I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows: ALTER PROCEDURE [dbo].[insert_department] @Name [varchar](100) AS BEGIN INSERT [dbo].[Departments]([Name]) VALUES (@Name) DECLARE @DeptId int SELECT @DeptId = [DeptId] FROM [dbo].[Departments] WHERE @@ROWCOUNT > 0 AND [DeptId] = SCOPE_IDENTITY() SELECT t0.[DeptId] … Read more

SQL Server: Query fast, but slow from procedure

A query runs fast: DECLARE @SessionGUID uniqueidentifier SET @SessionGUID = ‘BCBA333C-B6A1-4155-9833-C495F22EA908’ SELECT * FROM Report_Opener WHERE SessionGUID = @SessionGUID ORDER BY CurrencyTypeOrder, Rank subtree cost: 0.502 But putting the same SQL in a stored procedure runs slow, and with a totally different execution plan CREATE PROCEDURE dbo.ViewOpener @SessionGUID uniqueidentifier AS SELECT * FROM Report_Opener WHERE … Read more

How to check if a stored procedure exists before creating it

I have a SQL script that has to be run every time a client executes the “database management” functionality. The script includes creating stored procedures on the client database. Some of these clients might already have the stored procedure upon running the script, and some may not. I need to have the missing stored procedures … Read more

SQL Server Insert if not exists

I want to insert data into my table, but insert only data that doesn’t already exist in my database. Here is my code: ALTER PROCEDURE [dbo].[EmailsRecebidosInsert] (@_DE nvarchar(50), @_ASSUNTO nvarchar(50), @_DATA nvarchar(30) ) AS BEGIN INSERT INTO EmailsRecebidos (De, Assunto, Data) VALUES (@_DE, @_ASSUNTO, @_DATA) WHERE NOT EXISTS ( SELECT * FROM EmailsRecebidos WHERE De … Read more