22

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.

8
  • 3
    Why is LastUpdate a varchar(200)? Sounds like a date column. Commented May 25, 2011 at 15:14
  • 1
    Sounds like it should be more than one column then - generally good practice is one column per piece of data. Commented May 25, 2011 at 15:17
  • 1
    It is not something big that I need to think about better practices. It is just a temp projects and all it is needed to handle the current tasks. Commented May 25, 2011 at 15:19
  • 6
    if you do bad design often, when it doesn't matter, then you will end up doing bad design when it does matter. NEVER put multiple pieces of data in a single column you will forever be parsing out your values, just create multiple columns, it is really easy to do this the right way, so why not? Commented May 25, 2011 at 15:39
  • 2
    Sometimes putting multiple pieces of data in a single column can significantly speed up and simplify your schema. For example, suppose you want to store the last 5 selected numbers. You could create a table, a relation, and store 5 records in the database. Or, you can store a string list 1,2,3,4,5. If you have no reason to do any special processing on 1,2,3,4,5 then store it as a list. To say NEVER put multiple pieces of data in a single column just isn't always the case. If needed you could always add the relational table at a future date. Commented Feb 12, 2014 at 16:49

4 Answers 4

35

The syntax you need is

ALTER TABLE Products ADD LastUpdate  varchar(200) NULL

This is a metadata only operation

Sign up to request clarification or add additional context in comments.

3 Comments

@manosivam - I rejected your edit. The default nullability for new columns depends on session and database options and should not be assumed.
Link, you've given, points to a web page, that loads enormous amount of ads and external links to right sidebar, while leaving main page text completely empty. So I assume, that we may call that link "dead" or at least unusable.
@trejder - Thanks for the heads up. Looks like it is moved to sqlmag.com/blog/…
9

What about something like:

Alter Table Products
Add LastUpdate varchar(200) null

Do you need something more complex than this?

Comments

1

Its work perfectly

ALTER TABLE `products` ADD `LastUpdate` varchar(200) NULL;

But if you want more precise in table then you can try AFTER.

ALTER TABLE `products` ADD `LastUpdate` varchar(200) NULL AFTER `column_name`;

It will add LastUpdate column after specified column name (column_name).

Comments

-1
alter table table_name add field_name (size);

alter table arnicsc add place number(10);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.