ProgrammingBaKa
ProgrammingBaKa

Reputation: 373

Tsql add column using synonyms

I have to add two columns to a table

and I have a synonym associated with that table

For example:

My table name is table_abc and the synonyms is table_1

When i try to add column to the table in normal way,

ALTER TABLE [dbo].[table_1]
ADD test_1 varbinary(MAX),
test_2 varbinary(MAX);

Following error occurs :

Cannot alter 'dbo.table_1' because it is not a table.

Is there a correct way using synonyms to add a column to the table? or is it just a wrong way to add a column?

Thanks a lot!

Upvotes: 1

Views: 2050

Answers (2)

Chanukya
Chanukya

Reputation: 5893

You cannot alter table with alias name and you have to add column to the table in this way

ALTER TABLE [dbo].[table_abc]
    ADD test_1 varbinary(MAX)

and

ALTER TABLE [dbo].[table_abc]

ADD test_2 varbinary(MAX)

Upvotes: 1

We cannot alter Synonyms created on table in Sql Server.

We can only do

CREATE SYNONYM (Transact-SQL)
DROP SYNONYM (Transact-SQL)

If we want to alter main table

alter table table_abc
add test_1 varbinary(MAX),
test_2 varbinary(MAX);

**To get the table name from the synonym name **

SELECT  base_object_name,* FROM  sys.synonyms where name like'%Synonym name%'

Upvotes: 1

Related Questions