A common question asked of SQL Team is "How do I write a stored procedure that will create a table/database. I want to pass in the name" SQL Server will not allow this Create Table @TableName ( ID int NOT NULL Primary Key, FieldName VarChar(10) ) Once again, dynamic SQL to the rescue Declare @SQL VarChar(1000) SELECT @SQL = 'Create Table ' + @TableName + '(' SELECT @SQL = @SQL + 'ID int NOT NULL Primary Key, FieldName VarChar(10))' Exec (@SQL) |
|
來(lái)自: xue_dong5437 > 《mysql》