0

How do I add new column with no fields generated? It would be a new column added without the rows. I don't want NULL or empty values...

Is that possible?

This will create NULL values:

$sql = "ALTER TABLE translation ADD new_column VARCHAR( 255 )";   
Grasper
  • 1,293
  • 12
  • 26
  • That will add a new column for each row, so the new column is added to every one. Do you want to add a new field without increase your table size? Maybe you could create a new 1:1 table. I usually do it with text fields witch could be null. – fmgonzalez Jun 16 '14 at 14:41
  • You know that FIELD and COLUMN are same thing, right? – Nawed Khan Jun 16 '14 at 14:41
  • 1
    ok, new column without rows? – Grasper Jun 16 '14 at 14:42
  • A `TRUNCATE translation` will help, but that's probably not what you want (please don't do that on live data). You can't add a column to a table without 'rows'. If you add a column to a table all existing rows will get the default value for that column (either `NULL`, `''` or something else). In most situations `NULL` means 'no value', so live with that or go with a 1:1 table as fmgonzalez suggested. – Peter van der Wal Jun 16 '14 at 14:49
  • 1
    because I have problem with this http://stackoverflow.com/questions/24210650/php-import-cvs-file-into-mysql – Grasper Jun 16 '14 at 14:58

1 Answers1

0

You can use either "not null" or "default" thingie. Or them both.

ALTER TABLE `translation ` 
ADD COLUMN `new_column` VARCHAR(45) NOT NULL DEFAULT '1234' AFTER `courier_id`;

"NOT NULL" will prevent the column of having null state ever, and the "DEFAULT" will set a default value.

Konstantin Bodnia
  • 1,372
  • 3
  • 20
  • 43