Fórum Testar via SQL se existe campo ou tabela #355637
19/03/2008
0
Desde já agradeço
Estanieski
Curtir tópico
+ 0Posts
19/03/2008
Wanderok
query1.sql.clear;
query1.sql.add(´SELECT CLI_NOME FROM CLIENTE_CLI´);
try
query1.open;
except
// Nao tem a tabela ou nao tem o campo
// ( ou voce escreveu algo no sql ou no objeto kkkk :D:D:D
... criar um ou outro...
// pense ai... :D:D:D
end;
Abracao !
Gostei + 0
19/03/2008
Wanderok
/ ( ou voce escreveu algo ERRADO no sql ou no objeto kkkk
Gostei + 0
19/03/2008
Estanieski
Gostei + 0
19/03/2008
Wanderok
Gostei + 0
19/03/2008
Macario
O código abaixo é para SQL Server
[b:0e22a4ee63]Verifica se tabela existe:[/b:0e22a4ee63]
query1.close; query1.sql.clear; query1.sql.add(´select TB.name as [NOME DA TABELA]´); query1.sql.add(´from´); query1.sql.add(´ sysobjects as TB´); query1.sql.add(´where ´); query1.sql.add(´ TB.xtype = ´U´ and TB.name = ´QUALSUATABELA´´); query1.open; if query1.isEmpty then ShowMessage(´Tabela não existe´);
Verifica se campo existe em uma determinada tabela:
query1.close; query1.sql.clear; query1.sql.add(´select tb.name as [Nome da Tabela],´); query1.sql.add(´ co.name as [Nome da Coluna] ´); query1.sql.add(´from syscolumns as co ´); query1.sql.add(´inner join ´); query1.sql.add(´ sysobjects as tb on (tb.id=co.id) ´); query1.sql.add(´where tb.xtype = ´U´ and tb.name = ´TABELA´´); query1.sql.add(´ and co.name = ´CAMPO´´); query1.open; if query1.isEmpty then ShowMessage(´Campo não existe´);
Espero que ajude. 8)
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)