Board index » Visual Studio » [VBScript] Create new table in SQL server

[VBScript] Create new table in SQL server

Visual Studio265
Greetings.



I have created a database in SQL Server 2005 Express edition. Now I

would like to create tables in this database using vbscript. Fields in

all tables are the same. Does anyone know, how to do this?



Peter







--

mcmallar

------------------------------------------------------------------------

Posted via www.codecomments.com

------------------------------------------------------------------------


-
 

Re:[VBScript] Create new table in SQL server

mcmallar wrote:

Quote
Greetings.



I have created a database in SQL Server 2005 Express edition. Now I

would like to create tables in this database using vbscript. Fields in

all tables are the same. Does anyone know, how to do this?



Just create the sql statement (CREATE TABLE ... ) that creates the table and

run it via ADO.



You can also use something called DSO which I haven't gotten around to

investigating yet (I think it's the SQL 2005 version of DMO).



If you only need to copy the column names (no constraints, defaults, etc.) a

simple



select * into newtable from oldtable where 1=2



will do the trick. If you want to copy the data as well, leave off the

"where 1=2" part.



You can find more examples here: http://www.aspfaq.com/show.asp?id" rel="nofollow" target="_blank">www.aspfaq.com/show.asp=2029



Note: it sounds as if you may need some information about database

normalization: unless you are creating a partitioned database, it is usually

not a good idea to create duplicate tables as you are doing. Do some

googling or pick up a book about database design.



Bob Barrows



--

Microsoft MVP - ASP/ASP.NET

Please reply to the newsgroup. This email account is my spam trap so I

don't check it very often. If you must reply off-line, then remove the

"NO SPAM"





-