Como criar uma tabela só se ele não existir?

Firebird

23/10/2013

Em outros bancos, eu uso

CREATE TABLE IF NOT EXISTS TABELAX (CAMPO CHAR(1))

Como faço isto no Firebird?
Alessandro Yamasaki

Alessandro Yamasaki

Curtidas 0

Respostas

Alan Mario

Alan Mario

23/10/2013

pesquisei e não achei nada sobre o codigo em questão
GOSTEI 0
Rafael Cruz

Rafael Cruz

23/10/2013

amigo, tente assim que funciona!!!



SET TERM !! ;
EXECUTE BLOCK AS
BEGIN


if (not exists(select 1 from RDB$RELATIONS where rdb$relation_name = 'teste')) then
execute statement
'CREATE TABLE teste (
codigo INTEGER NOT NULL,
nome varchar(30) NOT NULL
);';

execute statement 'ALTER TABLE teste ADD CONSTRAINT PK_teste PRIMARY KEY (codigo)';


END!!
SET TERM ; !!


bom código
GOSTEI 0
Alex Lekao

Alex Lekao

23/10/2013

interessante isso ai... rsrsr

to de olho... rsrs
GOSTEI 0
POSTAR