Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

execute alter on another database

Posted on 2013-11-09
4
Medium Priority
?
169 Views
Last Modified: 2013-11-12
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
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 41

Expert Comment

by:Sharath
ID: 39636589
This query should work.

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

Did you try?
0
 

Author Comment

by:ethar1
ID: 39636620
yes I try as written above and I got the error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Test2DB'.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 39636645
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
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39636662
ALTER TABLE [Test2DB].[dbo].[testTable]  DROP COLUMN ColName ;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question