if statement - Add column with FK to an existing table in MySQL 5.6 -


good day everyone. hope can helps me in experiments.

i have simple table needs , it's have data inside.

create table if not exists main.test ( id int(11) not null,  name varchar(30) not null,  date_created timestamp not null,  primary key (id)); 

but should update table adding column fk_.

how can check if table had has field fk_? if such column not exist do:

alter table main.test add column fk int(11), add foreign key (fk) references test2(id_test2) 

as use java decision of problem using resultset.

resultset set = statement.executequery(query); set.next(); int result = set.getint(1); //it return 1 row set.close(); 

and sql-query:

select count(column_name) information_schema.columns table_schema = 'main' , table_name = 'test' , column_name = 'fk"; 

when i'll result can decide query should use.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -