在mysql中动态创建表

时间:2014-03-10 11:56:04

标签: mysql asp.net

如何使用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))

2 个答案:

答案 0 :(得分: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

希望这有效

答案 1 :(得分:0)

CREATE procedure uspCalculateSalary_R( IN empid bigint, in IDType  varchar(1), in Monthy datetime , in Yeary datetime)
BEGIN


   CREATE  TABLE  SalaryTable (Empid bigint, EmpName varchar(100), Desig 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),ELPrev numeric(5,2),
   OthIncome_TN Decimal(8,0), OthDeduction_TN Decimal(8,0), OthIncome_NN Decimal(8,0), OthDeduction_NN Decimal(8,0), ELBal numeric(5,2),
   GrossSalary Decimal(8,0), TDS Decimal(7,0), EMI Decimal(8,0),NetSalary Decimal(8,0)) ;
end