新建一个存储过程
1-- ================================================
2-- Template generated from Template Explorer using:
3-- Create Procedure (New Menu).SQL
4--
5-- Use the Specify Values for Template Parameters
6-- command (Ctrl-Shift-M) to fill in the parameter
7-- values below.
8--
9-- This block of comments will not be included in
10-- the definition of the procedure.
11-- ================================================
12SET ANSI_NULLS ON
13GO
14SET QUOTED_IDENTIFIER ON
15GO
16-- =============================================
17-- Author: <Author,,Name>
18-- Create date: <Create Date,,>
19-- Description: <Description,,>
20-- =============================================
21CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
22 -- Add the parameters for the stored procedure here
23 <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
24 <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
25AS
26BEGIN
27 -- SET NOCOUNT ON added to prevent extra result sets from
28 -- interfering with SELECT statements.
29 SET NOCOUNT ON;
30
31 -- Insert statements for procedure here
32 SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
33END
34GO
35
2-- Template generated from Template Explorer using:
3-- Create Procedure (New Menu).SQL
4--
5-- Use the Specify Values for Template Parameters
6-- command (Ctrl-Shift-M) to fill in the parameter
7-- values below.
8--
9-- This block of comments will not be included in
10-- the definition of the procedure.
11-- ================================================
12SET ANSI_NULLS ON
13GO
14SET QUOTED_IDENTIFIER ON
15GO
16-- =============================================
17-- Author: <Author,,Name>
18-- Create date: <Create Date,,>
19-- Description: <Description,,>
20-- =============================================
21CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
22 -- Add the parameters for the stored procedure here
23 <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
24 <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
25AS
26BEGIN
27 -- SET NOCOUNT ON added to prevent extra result sets from
28 -- interfering with SELECT statements.
29 SET NOCOUNT ON;
30
31 -- Insert statements for procedure here
32 SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
33END
34GO
35
SET ANSI_NULLS ON
当 SET ANSI_NULLS 为 ON 时,即使 column_name 中包含空值,使用 WHERE column_name = NULL 的 SELECT 语句仍返回零行。
即使 column_name 中包含非空值,使用 WHERE column_name <> NULL 的 SELECT 语句仍会返回零行。
当 SET ANSI_NULLS 为 OFF 时,等于 (=) 和不等于 (<>) 比较运算符不遵从 SQL-92 标准。使用 WHERE column_name = NULL 的 SELECT 语句返回 column_name 中包含空值的行。使用 WHERE column_name <> NULL 的 SELECT 语句返回列中包含非空值的行。此外,使用 WHERE column_name <> XYZ_value 的 SELECT 语句返回所有不为 XYZ_value 也不为 NULL 的行。
SET QUOTED_IDENTIFIER ON
当 SET QUOTED_IDENTIFIER 为 ON 时,标识符可以由双引号分隔,而文字必须由单引号分隔。
当 SET QUOTED_IDENTIFIER 为 OFF 时,标识符不可加引号,且必须符合所有 Transact-SQL 标识符规则。