Home > database >  How to determine when adding table field field does not exist to add?
How to determine when adding table field field does not exist to add?

Time:09-27

How to determine when adding table field field does not exist to add?
The following statement:
The ALTER TABLE t1 ADD col1 VARCHAR (1) NOT NULL
I want to judge the existence of col1 column in the t1 table and if not, just to add, if there is not to add,

Thank you for your attention

CodePudding user response:

IF not the exists (SELECT 1 FROM information_schema. The columns WHERE table_schema='aaa' AND table_name='t1' AND column_name='col1')
THEN
The alter table t1 add col1 varchar (20) not null;
END the IF
  • Related