Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql alter table add column first

-- 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 first position mysql

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)
Comment

add column to all tables after first column mysql

SELECT CONCAT('ALTER TABLE ', table_schema,'.', TABLE_NAME,' ADD COLUMN `hash` VARCHAR(50) NULL DEFAULT UUID() AFTER ', first_column, ';') AS ddl

FROM (

	SELECT
		(
			SELECT `COLUMN_NAME`
			FROM `INFORMATION_SCHEMA`.`COLUMNS`
			WHERE `TABLE_SCHEMA`=t.TABLE_SCHEMA AND `TABLE_NAME`=t.TABLE_NAME
			LIMIT 1
		) AS 'first_column',
		t.*
	FROM
	information_schema.tables t
	WHERE table_schema = 'your_table_name' AND table_type = 'base table'
	
) AS x;
Comment

PREVIOUS NEXT
Code Example
Sql :: app times 
Sql :: 000webhost database values insert 
Sql :: pl sql oracle trigger update exclude site:stackoverflow.com 
Sql :: query builder doctrien return sql 
Sql :: ORACLE multiset union distinct 
Sql :: mysql coonect sample code 
Sql :: SQL MAX() and MIN() with Strings 
Sql :: recursive query herarchical data sql server 
Sql :: db connection using sql client in dot net 
Sql :: How to concatenate text from multiple rows into a single text string in SQL Server 
Sql :: mysql delete connected entries from database 
Sql :: where field is null sql knex 
Sql :: mysql find char in string 
Sql :: teller stamp , bmo , PDF 
Sql :: sql eomonth(getdate) 
Sql :: sql Contain declare sample 
Sql :: MYSQL create new query tab 
Sql :: get db connection detail from sql developer profile 
Sql :: if new such record in where condition in sql so what is return 
Sql :: select function with the column name we want to select 
Sql :: What is the library that should import to use all functional database features in SQLite? 
Sql :: edit a field mysql terminal 
Sql :: minecraft duping allowed servers 
Sql :: oracle timestamp +1h 
Sql :: Time difference in hh:mm:ss 
Sql :: mysql update sequence with order by 
Sql :: oracle pl/sql check if file exists 
Sql :: case sensitive sql 
Sql :: check mysql password with docker container magento 2 
Sql :: sql promises req, res 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =