I tried the following query in SQL Server 2000 so that I could add a new column after mentioned column.
alter table abc ADD dad varchar(50) after parentname
But it throws me the following error message
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'after'.
Is there any way to do this in SQL Server 2000?
In Microsoft SQL Server, we can change the order of the columns and can add a new column by using ALTER command. ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.
You can use the ALTER table command to change the length of a varchar column. You can increase the length of a varchar column to a maximum size of 64,000.
For example: ALTER TABLE employees ADD last_name VARCHAR(50), first_name VARCHAR(40); This SQL Server ALTER TABLE example will add two columns, last_name as a VARCHAR(50) field and first_name as a VARCHAR(40) field to the employees table.
To add a column at a specific position within a table row, use FIRST or AFTER col_name . The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.
In SQL Server there is no syntax such.
Just use
ALTER TABLE abc ADD dad varchar(50)
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