PDA

Click to See Complete Forum and Search --> : How to create a database in SQL Server from VB


gorthims
May 4th, 2000, 04:40 PM
How can i create a database in SQL server from vb

Ianpbaker
May 4th, 2000, 07:28 PM
Hi gorthims

To create A new database IN VB you have to do it in two sections.

Firstly if you want to use new devices for the database you need to do the following.

Set a connection to the server then use the following code

myconnection.execute "DISK INIT Name = `NewDevice'," & _
"PhysName = `C:\SQL65\DATA\NewDevice.DAT'," & _
"VDevNo = 6," & _
"Size = 2500"

This Will only work in SQL6.5 And not seven but if you are using 7.0 and I remember correctly, seven automatically creates the devices for you

Next

Once the deivices are created or if you want to use existing ones use the follwing code

myconnection.execute "CREATE DATABASE database_name" & _
"[ON {DEFAULT | database_device} [= size]" & _
"[, database_device [= size]]...]" & _
"[LOG ON log_device [= size]" & _
"[,log_device[= size]]...]" & _
"[FOR LOAD]"

Most of those options speak for themselves but you can look in books-online for further information.

And there you have it one brand new spanking database sitting on your server.

Finally you can use the create table statement to yes, youve got it :rolleyes:, craete tables for your new database.

If you need any more help, reply back

Hope this helps ;)
Ian

gorthims
May 4th, 2000, 08:50 PM
ThanQ Ianpbaker

This will help me.