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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Create table using procedure

Author  Topic 

iswan
Starting Member

28 Posts

Posted - 2007-04-05 : 03:42:40

How create the table using procedure or function. the table name comes from a procedure as parameter

Code: i tried
create procedure #Isw_tab @TableName VARCHAR(1000)
as
EXEC ('CREATE TABLE '+@TableName+'(Age int)')

exec #Isw_tab '#isw1';


It is not creating the table

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 03:55:01
That should be the bad db design
Why do you need to create tables on the fly?
Pre-create the table and access data through the procedure

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

iswan
Starting Member

28 Posts

Posted - 2007-04-05 : 04:02:21
I get the Table name, Field name from the front end (i.e Asp page). So I need to create the table or alter the table through procedure

Iswan

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 04:18:46
quote:
Originally posted by iswan

I get the Table name, Field name from the front end (i.e Asp page). So I need to create the table or alter the table through procedure

Iswan



Thats what I told you that is the bad design
Why do you need this?
Can you give me practical example for this?
Note that with this approach, your interaction with dataase will become too complex with too much use of dynamic sql

Also before dynamically executing, print that sql and see if the statement is valid

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-05 : 04:22:56
Whoa!!!

1. Creating temporary stored procedure
2. Passing table name as parameter
3. Creating table dynamically from SP
4. The table that needs to be created is local temp table!

There are too much loose ends here ...I am leaving !

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -