PDA

View Full Version : Check for table existance


Anguinus
03-16-2004, 12:32 PM
I am using webspace on www.brinkster.com and am therefore using SQL to query an Access2000 database.

Can anyone advice me on what code to use for checking for the existance of a table in the database and then creating one if its not there?

Thanks

fyrye
05-16-2004, 02:33 AM
not sure about what components brinkster has installed, but use OpenSchema, along with your regular connection to the database.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthopenschema.asp

using the adSchemaTables

you can do something like this
Set rsTemp = server.createObject("adodb.recordset")
rsTemp.Open ConnTemp.OpenSchema(adSchemaTables)

then call for the tables like so
While Not rsTemp.EoF
response.write rsTemp("Table_Name")
rsTemp.MoveNext
WEnd

*EDIT*
As far as creating the table, use SQL for that as well

SQL = "Create Table TableName " & _
"Field_ID int IDENTITY NOT NULL constraint" & _
"Field_ID PRIMARY KEY"