-3
ALTER TABLE {abc_in} ADD COLUMN abcd_nid int(10) unsigned NOT NULL default '0' AFTER abcd_in

What if column abcd_nid already exists ? Will it be overwritten ? how can I insert new values into column ?

2
  • which DBMS do you use? In DB2 you'll get an error message. You should try it out, if you can. Changing the values from default to something else can easily be done with "update {abc_in} set abcd_nid = ... where ..."
    – kasia.b
    Commented Sep 16, 2013 at 13:07
  • 2
    this is easily testable by creating a test database (which you should have on your development machine!) and executing the statement in your question twice. The 2nd time, you will receive an error explaining that you cannot add a field when it already exists.
    – Hannah Vernon
    Commented Sep 16, 2013 at 14:47

1 Answer 1

2

You did not mention which database you are using, however trying to add a column that already exists will produce an error. All the databases that I have worked with require a column name to be unique within a table. (No room for two abcd_nid columns.)

To update the column you use the standard UPDATE command.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.