Those are default values produced by SSMS when you script objects. They are not needed at all, and not needed to be duplicated between procs.
how to use SET ANSI_NULLS ON in a script wich creates several sprocs?
I have seen this script in docs. why does it repeat SET ANSI_NULLS ON and SET QUOTED_IDENTIFIER ON
before each batch that creates a sproc?. Is it necessary at all repeating them? or just the first ones would work the same?
USE [master]
GO
CREATE DATABASE [MySchool]
GO
USE [MySchool]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[CourseExtInfo] @CourseId int
as
select c.CourseID,c.Title,c.Credits,d.Name as DepartmentName
from Course as c left outer join Department as d on c.DepartmentID=d.DepartmentID
where c.CourseID=@CourseId
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[DepartmentInfo] @DepartmentId int,@CourseCount int output
as
select @CourseCount=Count(c.CourseID)
from course as c
where c.DepartmentID=@DepartmentId
select d.DepartmentID,d.Name,d.Budget,d.StartDate,d.Administrator
from Department as d
where d.DepartmentID=@DepartmentId
GO
Developer technologies Transact-SQL
1 additional answer
Sort by: Most helpful
-
Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
2021-02-02T22:26:09.157+00:00 Just to expand on Tom's reply. These settings are saved with the procedure definition and will override the run-time setting. This is why SSMS includes them in the script. And I guess that since they are properties of the procedure, SSMS scripts them once for every procedure - just in case you would like to change for one of them.
But you to want to these settings. The OFF settings are legacy settings and should never be used.