+ 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.
12 Réponses
+ 3
First add column then update column value
+ 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
+ 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)
+ 2
UPDATE table_name SET column_name = value WHERE primaryid_value = ?
+ 2
Patrick Noulet
Show your complete script
+ 2
Patrick Noulet
You have to update Gender column on primary id which are 1, 2, 3, 4
I already told you update script
+ 1
Ok, I have seen What went wrong in my code, thanks A͢J
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
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.
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');
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.
0
Could you please show me an example of the code