Board index » delphi » Ado Command Object

Ado Command Object


2005-02-10 04:10:21 PM
delphi135
hi,
I am using Delphi7 and Sql server2000. How can I check whether the
temporary tables created using ADOcommand object (In sql i.e create table)
for its existance. I am actually creating a table in formcreate and deleting
the records on close. So next time when I open the form I want to check for
its existance. If does not exist then only create other wise skip. Something
like
if Table1.exist then. How can I achieve the same here.
Please give me your valuable suggestions on this
Thanks,
 
 

Re:Ado Command Object

Hi,
Try using Sp_Tables. it is a stored procedure which will give you a list of
the tables of the current database.
--
Best regards
Guillem Vicens
Dep. informática Green Service SA
XXXX@XXXXX.COM
www.clubgreenoasis.com
"Antony" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
hi,
I am using Delphi7 and Sql server2000. How can I check whether the
temporary tables created using ADOcommand object (In sql i.e create table)
for its existance. I am actually creating a table in formcreate and
deleting
the records on close. So next time when I open the form I want to check
for
its existance. If does not exist then only create other wise skip.
Something
like
if Table1.exist then. How can I achieve the same here.
Please give me your valuable suggestions on this
Thanks,


 

Re:Ado Command Object

Antony writes:
Quote
hi,
I am using Delphi7 and Sql server2000. How can I check whether the
temporary tables created using ADOcommand object (In sql i.e create table)
for its existance. I am actually creating a table in formcreate and deleting
the records on close. So next time when I open the form I want to check for
its existance. If does not exist then only create other wise skip. Something
like
if Table1.exist then. How can I achieve the same here.
Please give me your valuable suggestions on this
Lots of ways to do this. You could execute "'SELECT TOP 1 * FROM
tb_table" - if you get an empty recordset there's no table. This
is useful if you don't know in advance what database engine you're
going to be using.
Or you can look at ADO's OpenSchema method in the Delphi help.
Or under SQL server you can query the sysobjects table. (I.e
SELECT * FROM sysobjects WHERE name = 'tb_table' AND xtype = 'U').
Or as Guillem says, there's sp_tables (which is a fancy way to
query sysobjects). But this would give you a result set which
you'd have to loop through; I prefer a single SQL statement where
if the resulting recordset is EOF the table doesn't exist.
--
jc
Remove the -not from email
 

Re:Ado Command Object

do sql command:
if not exists (select * from dbo.sysobjects where id =
object_id(N'[MyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [MyTable] (.....)
--Creates MyTable only if not existing
heinrich
Antony schrieb:
Quote
hi,
I am using Delphi7 and Sql server2000. How can I check whether the
temporary tables created using ADOcommand object (In sql i.e create table)
for its existance. I am actually creating a table in formcreate and deleting
the records on close. So next time when I open the form I want to check for
its existance. If does not exist then only create other wise skip. Something
like
if Table1.exist then. How can I achieve the same here.
Please give me your valuable suggestions on this
Thanks,