Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql add column if not exists

ALTER TABLE test ADD COLUMN IF NOT EXISTS column_a VARCHAR(255);
Comment

add column if not exists mysql

-- ALTER TABLE tbl_name ADD COLUMN column_name column_definition 
--		[FIRST|AFTER existing_column];
ALTER TABLE office ADD COLUMN phone VARCHAR(200) DEFAULT '000' AFTER name;
ALTER TABLE office ADD COLUMN flag INT(1) FIRST;
ALTER TABLE office ADD COLUMN last_col INT(2);	-- Last column is default position
-- ↓ Test it (Fiddle)
Comment

add column if not exists mysql

SELECT count(*) INTO @EXIST
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'mydatabase'
  AND COLUMN_NAME = 'mycolumn'
  AND TABLE_NAME = 'mytable' LIMIT 1;

SET @query = IF (@exist <= 0, 'ALTER TABLE mydatabase.`mytable`  ADD COLUMN `mycolumn` MEDIUMTEXT NULL',
    'select ' COLUMN EXISTS' status');
PREPARE stmt FROM @query;
EXECUTE stmt;
Comment

PREVIOUS NEXT
Code Example
Sql :: how to find sql server agent jobs related to a database 
Sql :: print year of a date sql 
Sql :: use concat in group_concat 
Sql :: pl/sql cursor 
Sql :: sql column contains special character 
Sql :: how to truncate table with foreign key constraint postgresql 
Sql :: How to check event scheduler status mysql 
Sql :: mysql cashing error 
Sql :: postgresql add leading zeros 
Sql :: run sql command line download for windows 10 
Sql :: plsql print 
Sql :: error code 1451 sql 
Sql :: sql select into 
Sql :: get record which is available in one table but not in another mysql 
Sql :: condition in count sql 
Sql :: sql case 
Sql :: current date in postgresql minus 1 day 
Sql :: sqlite autoincrement 
Sql :: python pandas df to postgres json table 
Sql :: postgre describe table 
Sql :: oracle tablespace tables list 
Sql :: mysql delete table with foreign key 
Sql :: in mysql workbench contnent not feching 
Sql :: mysql 1 hour ago 
Sql :: postgresql contains 
Sql :: output table plsql 
Sql :: version and edition of SQL Server Database Engine 
Sql :: creating index in mysql 
Sql :: sql injection payload list github 
Sql :: current date in sql 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =