Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lakon15
Starting Member
12 Posts |
Posted - 2007-12-19 : 03:02:11
|
| Dear All, I want to create store procedure to create new table, I already make with single column, but this is not what I want to,What I want to is make new table with many columns not a single column and I don't want to use hard code as sent all columns and datatype as parameter.Is there any way to create SP like this ? Thank's Before create PROCEDURE [dbo].[spCreateNewTable] @uidPath varchar(325), @columnName Varchar(64), @columnIndex varchar(64)AS Declare @query varchar(1000), @pathHash bigint -- convert path to hash Set @pathHash= [dbo].fnFNVHash(@uidPath) -- Create New table Select @query='Create table WMData_'+cast(@pathHash as Varchar(64))+'(' Select @query=@query + @ColumnName+' Real ) CREATE CLUSTERED INDEX [IX_WMLogData_'+cast(@pathHash as Varchar(64))+'] ON [WMLogData_'+cast(@pathHash as Varchar(64))+'] ( ['+@columnIndex+'] ASC )' Exec(@query) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-19 : 03:08:03
|
| Why do you want to create a table dynamically?Refer www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
lakon15
Starting Member
12 Posts |
Posted - 2007-12-19 : 03:21:14
|
| we want to make dynamic table, because when parent table create new column automatic create new table base on that new column in parent table. Let say if parent table add new column with path a, it's automatic create new table with name WMData_path, columns number in every table with prefix WMData_ will be different it refer to that path,That's why I need to make dynamic table |
 |
|
|
|
|
|