[T-SQL] [저장 프로세스 실례]
4741 단어 t-sql
USE [SchoolDB]
GO
/****** : Table [dbo].[WZOU_SysPermission] : 10/28/2014 11:05:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WZOU_SysPermission](
[TeacherId] [nchar](8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Specialty] [nvarchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ClassName] [nvarchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Permission] [bigint] NOT NULL,
[Remark] [nvarchar](512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_WZOU_SysPermission] PRIMARY KEY CLUSTERED
(
[TeacherId] ASC,
[Specialty] ASC,
[ClassName] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N' ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WZOU_SysPermission', @level2type=N'COLUMN',@level2name=N'TeacherId'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N' ( DicType=05)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WZOU_SysPermission', @level2type=N'COLUMN',@level2name=N'Specialty'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N' ( DicType=07)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WZOU_SysPermission', @level2type=N'COLUMN',@level2name=N'ClassName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N' ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WZOU_SysPermission', @level2type=N'COLUMN',@level2name=N'Permission'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N' ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WZOU_SysPermission', @level2type=N'COLUMN',@level2name=N'Remark'
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATEPROCEDURE [dbo].[UpdateSysPermission]
-- Add the parameters for the stored procedure here
(
@TeacherId nchar(8),
@Specialty nvarchar(16),
@ClassName nvarchar(16),
@Permission bigint,
@Remark nvarchar(512) = ''
)
AS
BEGIN
DECLARE @StrSQL NVARCHAR(2000)
DECLARE @Count int
SELECT @Count=count(*) FROM WZOU_SysPermission WHERE TeacherId=@TeacherId AND Specialty=@Specialty AND ClassName=@ClassName
SET @StrSQL = 'SELECT * FROM WZOU_SysPermission WHERE TeacherId = N''' + @TeacherId + ' AND Specialty = N'''+ @Specialty +' AND ClassName = N''' + @ClassName
PRINT(@Count)
IF EXISTS(SELECT * FROM WZOU_SysPermission WHERE TeacherId=@TeacherId AND Specialty=@Specialty AND ClassName=@ClassName)
BEGIN
PRINT(@StrSQL)
END
IF (@Count = 0)
BEGIN
SET @StrSQL = 'INSERT INTO WZOU_SysPermission (TeacherId, Specialty, ClassName, Permission, Remark) VALUES(N''' + @TeacherId + ''', N''' + @Specialty + ''', N''' + @ClassName + ''', ' + convert(nvarchar,@Permission) + ', N''' + @Remark + ''')'
END
ELSE
BEGIN
SET @StrSQL = 'UPDATE WZOU_SysPermission SET Permission = ' + convert(nvarchar,@Permission) + ', Remark = N''' + @Remark + ''' WHERE (TeacherId = N''' + @TeacherId + ''' AND Specialty = N''' + @Specialty + ''' AND ClassName = N''' + @ClassName + ''')'
END
PRINT(@StrSQL)
EXEC(@StrSQL)
END
//
UpdateSysPermission @TeacherId='00000000',@Specialty=N' ',@ClassName=N'1 ',@Permission= 3
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
T-sql 귀속 구조 연속 날짜 시퀀스텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.