美文网首页
MSSQL存储过程建表

MSSQL存储过程建表

作者: _意义 | 来源:发表于2021-01-25 15:10 被阅读0次
USE [ARC_DB]
GO
/****** Object:  StoredProcedure [dbo].[SP_CreateTable_ArcRecord]    Script Date: 2021/1/25 14:57:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_CreateTable_ArcRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
ALTER PROCEDURE [dbo].[SP_CreateTable_ArcRecord]
AS
BEGIN   
--设置年
    declare @year varchar(10);
    set @year = CONVERT(varchar(4), GETDATE(), 23);
    declare @tbName varchar(60);
    set @tbName = ''ARC_RECORD_'' + @year;
    DECLARE @Sql VARCHAR(MAX) = ''
    IF OBJECT_ID(''''[dbo].[''+@tbName+'']'''') IS NULL
        BEGIN
            CREATE TABLE [dbo].[''+@tbName+'']
            (
                [ID] [varchar](36) NOT NULL,
                [ARC_LOG_ID] [nvarchar](36) NULL,
                [ARC_PATH] [nvarchar](500) NULL,
                [ARC_TIME] [datetime] NULL,
                [SERIAL_NUMBER] [nvarchar](50) NULL,
                [TASK_ID] [nvarchar](36) NULL,
                [LICENSE_PLATE_NUMBER] [nvarchar](50) NULL,
            )
        END
   ''

    EXEC(@Sql)

END

' 
END

相关文章

网友评论

      本文标题:MSSQL存储过程建表

      本文链接:https://www.haomeiwen.com/subject/qmxizktx.html