简体   繁体   中英

How we can add new Coulmn if not exist using SQL for Apache Derby Database/JavaDB

How we can add new Coulmn if not exist using SQL for Apache Derby Database/JavaDB

I know that we can add new coulmn using the SQL:

alter table Country ADD  Language  varchar(10)

But I need to add if not exist because sometimes this coulmn exisit and derby give me errors.

You can find out which columns already exist in the table by consulting the DatabaseMetadata : call the getColumns method. Here's the Javadoc: https://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getColumns(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM