Click here to Skip to main content
15,867,765 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an existing table. I know I have to alter the table and add the values to the new column. My sql command is
ALTER TABLE PRODUCT
ADD PROD_CHARGE NUMERIC(30)
INSERT VALUES INTO MODE(...)

for example I have three existing attributes and it have values already after I added my new column in the existing table for my new column the values are given corresponding to each attribute and value for new column as well.
I am stuck here because there are existing columns and I have to add values corresponding to each attribute in my new attribute. Please help thank you

What I have tried:

ALTER TABLE PRODUCT
ADD PROD_CHARGE NUMERIC(30)
INSERT VALUES INTO MODE(...)
Posted
Updated 16-Jul-22 18:38pm

INSERT works on records not individual columns. If you want to add values to the new column, you have to use an UPDATE query.
SQL
UPDATE tableName
SET columnName = value
[WHERE ...]
If you're updating every record in the table, you don't need the WHERE clause.

Beyond that, it's not very clear what you're trying to do.
 
Share this answer
 
To add to what Dave has - rightly - said, I'd add a DEFAULT value to the column as well when you add it to the table - that way, event row gets a new value that makes sense.
And if you are going to then set every row's value to the same number anyway, adding a default will do that at the moment the row is changed which in a multiuser DB like MySql is probably important.
SQL DEFAULT Constraint[^]
 
Share this answer
 
I have an existing table. It has several attributes and I have to alter
the table using new attribute the att name is given description is given, the data type and values that is corresponding the existing columns values. Since the new column contains $100 I am not sure if it will be numeric data type since $ is involved.

I have been using UPDATE but do I have to set values for all the existing columns?
 
Share this answer
 
Comments
Dave Kreskowiak 17-Jul-22 0:49am    
First, you posted this as an answer to your own question. Nobody else gets a notification that you posted this.

You already posted this in the original question and it still does not make sense. Reposting it does not help.

You have to provide examples of what you're trying to do. What data (values) are in what table/columns and what are you looking to put in the new column?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900