Ramani Ranjan
January 28th, 2000, 05:42 AM
Hi Friends,
Can anybody help me to create tables using SQL DMO from VB with Primary Key and all database objects.
Lothar Haensler
January 28th, 2000, 06:00 AM
here is a sample that uses SQLOLE. The methods are the same in SQLDMO.
Just replace SQLOLE with SQLDMO.
Tested with SQLServer 6.5 on NT 4 VB 6
Dim s as SQLOLE.SQLServer
set s = new SQLOLE.SQLServer
s.Connect "yourserver", "sa", ""
Dim t as new SQLOLE.Table
Dim col as new SQLOLE.Column
col.Name = "test"
col.Datatype = "varchar"
col.Length = 10
col.AllowNulls = false
t.Columns.Add col
set col = new SQLOLE.Column
col.Name = "test2"
col.Datatype = "varchar"
col.Length = 5
col.AllowNulls = true
t.Columns.Add col
t.Name = "mytesttable"
Dim k as new SQLOLE.Key
k.Clustered = true
k.Type = SQLOLEKey_Primary
k.KeyColumns.Add "test"
t.Keys.Add k
't.PrimaryKey = "test"
s.Databases("einzeltest").Tables.Add t
s.Disconnect