cclark413
cclark413

Reputation: 435

Adding a required column to a database table

If I were to add a column (i.e. EIN Tax ID) to an already existing database for my customers,would there be any effect on the already existing customers who may not have anything in that field when I request that information be put in the customer sign up form?

We have over 3000 customers, so I don't want to interrupt them by adding that for any new customer accounts.

Upvotes: 1

Views: 6997

Answers (4)

kerrin
kerrin

Reputation: 3452

If this is for Zen Cart, there is already an add-on for this.

See http://www.zen-cart.com/downloads.php?do=file&id=1137 - Extra Fields for Customer Sign Up (Create Account) Page.

Upvotes: 2

Matthew Auld
Matthew Auld

Reputation: 408

I'm going to make the assumption that you are using MySQL or SQL as your database and by default you can set a new column anywhere in the database without interrupting the current information. You can also set a DEFAULT value to the column so that every costumer in the table will have that values set to their account. I also recommend if altering the database please look over and of your insert queries because if you have a base query(below)

INSERT INTO `customers` VALUES(NULL,'myUsername','myPassword','myEmail');

It will no longer work. You will receive and SQL error. The easiest way to fix this is to set a direct query(below)

INSERT INTO `customers` (`id`,`username`,`password`,`email`) VALUES (NULL,'myUsername','myPassword','myEmail');

Hope this answers your question well. Happy coding.

Upvotes: 1

Samuel Cook
Samuel Cook

Reputation: 16828

You can set the default value for the column when you add it to the database so I wouldn't be too concerned there.

ALTER TABLE `table_name` ADD COLUMN `column_name` int(10) NOT NULL DEFAULT 0

The biggest concern is the existing way you add rows into the database and that you are defining the columns before hand.

For example:

INSERT INTO `table_name` VALUES ('col1','col2','col3').

The above statement would fail as the column count doesn't match, as you now have 4 columns (or however many).

INSERT INTO `table_name` (col1,col2,col3) VALUES ('col1','col2','col3')

The above statement would work fine, as you are defining the columns before hand, or the below:

INSERT INTO `table_name` SET col1='col1',col2='col2',col3='col3'

Upvotes: 3

Jason Bristol
Jason Bristol

Reputation: 401

If what you mean by required is NOT NULL then it will set the column to whatever the column DEFAULT value is set to for all 3000 records.

If what you mean is a PRIMARY KEY which by default is UNIQUE, then you would have to provide a value for all 3000 records or you could just set the column to AUTO INCREMENT and it will generate values

Upvotes: 1

Related Questions