Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create table

Status
Not open for further replies.

jebenson

Technical User
Feb 4, 2002
2,956
US
Well, there are a couple of different ways.

One is to use SQL Create Table syntax. A good basic reference is at:

[URL unfurl="true"]http://www.w3schools.com/sql/sql_create.asp[/url]

Or, you could use ADOX. To use ADOX, reference "Microsoft ADO Ext. 2.x for DDL and Security" and "Microsoft ActiveX Data Objects 2.x Library" under Project->References. Note: where the references have 2.x you will have a number, like 2.5. Then use this code (or similar):

Code:
Dim conn As ADODB.Connection
Dim tbl As ADOX.Table
Dim cat As ADOX.Catalog
Dim col As ADOX.Column

Set conn = New ADODB.Connection

'use your database and server names in connection string

conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<database-name>;Data Source=<SQLServer-name>"

conn.CursorLocation = adUseClient

conn.Open

Set cat = New ADOX.Catalog
cat.ActiveConnection = conn

Set tbl = New ADOX.Table

Set col = New ADOX.Column

tbl.Name = "ADOXTest"

col.Type = adVarChar
col.DefinedSize = 30
col.Name = "Field1"
tbl.Columns.Append col

Set col = Nothing
Set col = New ADOX.Column

col.Type = adInteger
col.DefinedSize = 4
col.Name = "Field2"
tbl.Columns.Append col

cat.Tables.Append tbl

Set conn = Nothing
Set cat = Nothing
Set tbl = Nothing
Set col = Nothing

Here is Microsoft's ADOX reference:

[URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoapireference.asp[/url]

Hope this helps.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Sorry jebenson, I was too late. It is very strange how we both put basically the same thing.

Swi
 
Hi all

How i can create a table in a SQL Server with some standard fields.

Thank for... you know
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top