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
 Development Tools
 Other Development Tools
 create table dynamically

Author  Topic 

husseinj
Starting Member

8 Posts

Posted - 2004-08-17 : 02:25:17
Hi everyone
I wish to create a table dynamically in sql server 2000 through vb 6.
Is that possible?
Thank you in advance

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-08-17 : 06:50:03
YES, why not!

- Sekar
Go to Top of Page

husseinj
Starting Member

8 Posts

Posted - 2004-08-17 : 06:57:27
But how?
Can you please help me find a way to do this please.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-08-17 : 07:22:10
exec('CREATE TABLE MyTable ( MyColumn1 varchar(10), MyColumn2 int)')

Kristen
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-08-17 : 07:23:20
Have you tried executing a CREATE TABLE statement in VB ??.. Are you getting any error ??...

- Sekar
Go to Top of Page

husseinj
Starting Member

8 Posts

Posted - 2004-08-17 : 07:54:15
quote:
Originally posted by samsekar

Have you tried executing a CREATE TABLE statement in VB ??.. Are you getting any error ??...

- Sekar



Am really sorry i have never done this
Could you please help me do this with some examples.
Thank you a lot
Go to Top of Page

amitkumarmadhukar
Starting Member

45 Posts

Posted - 2004-08-19 : 16:25:05
Hi Dear,
Very Easily , you Can Create Tables from VB there is two ways
1. Let assume you have a ADO Connection and Command Set Like and follow this Code
Cs.Commandtext="Create Table <TableName>(<FieldNames> <Variable_Type> (<Size>) <Identifier>,>(<FieldNames> <Variable_Type> (<Size>) <Identifier>,............,>(<FieldNames> <Variable_Type> (<Size>) <Identifier>)

Cs.Execute

and You Got your table
Ex:
Assume you have to Create Table named TEST , Which Fields are :Name,Address,Age,Sex then your code become to :
Cs.CommandText="Create table TEST(Name Varchar(50),Address Varchar(100),Age int,Sex Varchar(6))
Cs.Execute

and you get your table in database.


2. First You Develop a Stored Procedure for Creating Table look like:

Create Procedure MyTable
as
CREATE TABLE MyTable ( MyColumn1 varchar(10), MyColumn2 int)



and again supply commandtext,
Cs.commandText="Exec MyTable <Parameter Names>
Cs.Execute
and you again u get your table

isn't Easy Dear Please Reply me if you don't get help from above


amit kumar madhukar
Go to Top of Page
   

- Advertisement -