on 2015 Mar 02 6:06 AM
this is how i check if a table exists:
select 1 from systable where table_name = 'sometablename';
but how do i check if a column exists?
Thanks!
Request clarification before answering.
I guess this will do:
select 1 from syscolumn join systable on systable.table_id = syscolumn.table_id where table_name = 'MYTABLENAME' and column_name = 'MYCOLUMNNAME';
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here I have an update statement coded in such a fashion that it will only attempt to add the column if it doesn't already exist...
HTH
IF NOT EXISTS(SELECT 1 FROM SYS.SYSCOLUMNS WHERE creator = 'DBA' AND tname = 'Job' AND cname = 'ConcealedHauling') THEN ALTER TABLE "DBA"."Job" ADD "ConcealedHauling" INTEGER NULL DEFAULT 0; END IF;
So your are implicitly asking for a new "IF NOT EXISTS" clause for ALTER TABLE ADD modifications, something like?
ALTER TABLE ADD IF NOT EXISTS column-name [ AS ] column-data-type [ new-column-attribute ... ]
User | Count |
---|---|
41 | |
15 | |
10 | |
9 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.