Solved

execute alter on another database

Posted on 2013-11-09
4
152 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
4 Comments
 
LVL 40

Expert Comment

by:Sharath
Comment Utility
This query should work.

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

Did you try?
0
 

Author Comment

by:ethar1
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
ALTER TABLE [Test2DB].[dbo].[testTable]  DROP COLUMN ColName ;
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now