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 )";   
5
  • 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. Commented Jun 16, 2014 at 14:41
  • You know that FIELD and COLUMN are same thing, right? Commented Jun 16, 2014 at 14:41
  • 1
    ok, new column without rows? Commented Jun 16, 2014 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. Commented Jun 16, 2014 at 14:49
  • 1
    because I have problem with this stackoverflow.com/questions/24210650/… Commented Jun 16, 2014 at 14:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

if it's not null it will be empty value, I don't want rows at all.
Why would you need a column in this case?
because I have problem with this stackoverflow.com/questions/24210650/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.