gpt4 book ai didi

mysql - mysql动态创建表

转载 作者:行者123 更新时间:2023-11-30 00:34:16 24 4
gpt4 key购买 nike

如何在mysql中使用存储过程动态创建表?

Declare @SalaryTable Table(Empid bigint, EmpName varchar(100), 
Desigation bigint, Office bigint, BasicPay Decimal(8,0),
WorkingDay tinyint, Present numeric(4,2), SalaryDay numeric(4,2),
Overtime numeric(5,2), OthIncome Decimal(8,0),
OthDeduction Decimal(8,0), OthIncome_TA Decimal(8,0),
OthDeduction_TA Decimal(8,0), OthIncome_NA Decimal(8,0),
OthDeduction_NA Decimal(8,0), OthIncome_TN Decimal(8,0),
OthDeduction_TN Decimal(8,0), OthIncome_NN Decimal(8,0),
OthDeduction_NN Decimal(8,0), GrossSalary Decimal(8,0),
TDS Decimal(7,0), EMI Decimal(8,0), NetSalary Decimal(8,0))

最佳答案

创建新表的存储过程:

 CREATE PROCEDURE sproc_BuildTable 
@TableName NVARCHAR(128)
,@Column1Name NVARCHAR(32)
,@Column1DataType NVARCHAR(32)
,@Column1Nullable NVARCHAR(32)


AS

DECLARE @SQLString NVARCHAR(MAX)
SET @SQString = 'CREATE TABLE '+@TableName + '( '+@Column1Name+' '+@Column1DataType +' '+@Column1Nullable +') ON PRIMARY '

EXEC (@SQLString)

GO

希望这有效

关于mysql - mysql动态创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22299415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com