Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add one column into existing SQL Table

Tags:

I have a SQL Server table and it is located on a remote server. I can connect to it with SQL Server Management Studio but opening it takes time instead, I am doing my jobs with SQL Query window without reaching it.

Recently I've made a change on the local copy of this table and want to update the remote one as well. All I've done is adding one more column which is Nullable and I'd like to learn how to add this one more column to the remote SQL Server with T-SQL without ruining the remote one data.

Here is the additional info:

Table Name: Products

Columns to be added: LastUpdate, Nullable and varchar(200)

Thanks.

like image 483
Tarik Avatar asked May 25 '11 15:05

Tarik


People also ask

How do you add an existing column to a table?

To insert a column, pick any cell in the table and right-click. Point to Insert, and pick Table Rows Above to insert a new row, or Table Columns to the Left to insert a new column.

How do I add a column in SQL without losing data?

If you use ALTER TABLE statement, it will automatically add the new column to the end of the table. The ALTER privilege is required to perform this: ALTER TABLE table_name ADD col_name data_type NULL | NOT NULL; It will not drop any existing data.


1 Answers

The syntax you need is

ALTER TABLE Products ADD LastUpdate  varchar(200) NULL 

This is a metadata only operation

like image 193
Martin Smith Avatar answered Oct 31 '22 04:10

Martin Smith