How to add the column using alter by inputting the values on it? As the example, I want to add tempID's column which has value "3" on every row
Maybe it's something like this
ALTER TABLE NAMEYOURTABLE
ADD COLUMN last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
but the code above is only for the timestamp, not for integer values. Thanks in advance
Syntax. The basic syntax of an ALTER TABLE command to add a New Column in an existing table is as follows. ALTER TABLE table_name ADD column_name datatype; The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is as follows.
The syntax for adding a column with ALTER statement: ALTER TABLE table_name ADD new_column_name column_definition [FIRST | AFTER column_name];
In Object Explorer, right-click the table to which you want to add columns and choose Design. Select the first blank cell in the Column Name column. Type the column name in the cell. The column name is a required value.
Let's look at an example that shows how to add multiple columns to a table in SQL Server using the ALTER TABLE statement. For example: ALTER TABLE employees ADD last_name VARCHAR(50), first_name VARCHAR(40);
You should check out this https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
For your case it would be something like
ALTER TABLE NAMEYOURTABLE ADD COLUMN tempID int NULL DEFAULT 3;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With