• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

execute alter on another database

Dear all ,
Need to execute
 
alter [testTable]    drop column ColName ;  

Open in new window

which is belong to [Test2DB] while I am in context of [Master1DB].

I try to use :
 
alter [Test2DB].[testTable]    drop column ColName ;  

Open in new window

and
 
alter [Test2DB].[dbo].[testTable]    drop column ColName ;  

Open in new window


btw, I have  [testTable], ColName  in both database and all necessary permissions...
Also I don't want to use "USE" keyword.

thanks in advance.
0
ethar1
Asked:
ethar1
1 Solution
 
SharathData EngineerCommented:
This query should work.

alter [Test2DB].[dbo].[testTable]    drop column ColName ;  

Did you try?
0
 
ethar1Author Commented:
yes I try as written above and I got the error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Test2DB'.
0
 
Rajkumar GsSoftware EngineerCommented:
Try

alter Table [Test2DB].[dbo].[testTable]    drop column ColName ;  

Open in new window


Drop column Syntax is
ALTER TABLE <TableName> DROP COLUMN <column>

Raj
0
 
QuinnDexCommented:
ALTER TABLE [Test2DB].[dbo].[testTable]  DROP COLUMN ColName ;
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now