+ 1

How to insert a value to a column using the alter statement

I have created an already existing table, but I altered it so how can I create a create a column with a value.

10th Sep 2022, 12:54 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
12 Réponses
+ 3
First add column then update column value
10th Sep 2022, 1:02 PM
A͢J
A͢J - avatar
+ 3
Patrick Noulet There is Constraint DEFAULT also which you can set with default value while adding new column but all record will be updated with default value. So add new column with NULL and update column value on primary id
10th Sep 2022, 1:07 PM
A͢J
A͢J - avatar
+ 3
Patrick Noulet 1 - When you want to update single row UPDATE Subscription_users SET Gender = 'Male' WHERE ID = 1 2 - When you want to update all row UPDATE Subscription_users SET Gender = 'Male' 3 - When you want to update multiple row UPDATE Subscription_users SET Gender = 'Male' WHERE ID IN (1, 2, 3, 4)
10th Sep 2022, 5:44 PM
A͢J
A͢J - avatar
+ 2
UPDATE table_name SET column_name = value WHERE primaryid_value = ?
10th Sep 2022, 2:20 PM
A͢J
A͢J - avatar
+ 2
Patrick Noulet Show your complete script
10th Sep 2022, 4:07 PM
A͢J
A͢J - avatar
+ 2
Patrick Noulet You have to update Gender column on primary id which are 1, 2, 3, 4 I already told you update script
10th Sep 2022, 4:37 PM
A͢J
A͢J - avatar
+ 1
Ok, I have seen What went wrong in my code, thanks A͢J
12th Sep 2022, 6:59 AM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
0
Thanks A͢J but If you don't mind can you show me how I can insert values into the rows from the newly created column
10th Sep 2022, 1:45 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
0
When I was done creating the column through the alter statement, then I tried inserting values into the rows but it keeps showing null values.
10th Sep 2022, 3:55 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
0
CREATE DATABASE Sections USE Sections CREATE TABLE Subscription_users( ID INT NOT NULL AUTO_INCREMENT, FirstName VARCHAR (30) NOT NULL, LastName VARCHAR (30) NOT NULL, ) ; INSERT INTO Subscription_users(ID, FirstName,LastName) VALUES (1,'Caleb','Smith'), (2,'Anthony','Young'), (3,'Alexander','Thomas'), (4,'Williams','Martinelli');
10th Sep 2022, 4:27 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
0
This was the first code, then I decided to alter the table Subscription_users and included the column Gender, so how can I create a row for it, when it keeps telling me null values.
10th Sep 2022, 4:31 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar
0
Could you please show me an example of the code
10th Sep 2022, 5:16 PM
Ndeanaefo Chidalu
Ndeanaefo Chidalu - avatar