Help: SQL Server

Sharing my knowlege about SQL Server Troubleshooting Skills

  • Blog Stats

    • 2,156,997 hits
  • Select GETDATE()

    March 2026
    M T W T F S S
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031  

SSMS Tip: How to drop multiple objects?

Posted by blakhani on June 3, 2014


Have you even been into situation where you have to drop many tables in a database? Or drop multiple databases? As a developer, you might right click on each table/database and choose “delete”. If you are equipped with little T-SQL knowledge, you might write a script to do the same. Do you know that management studio can do it?

Let’s create multiple databases and learn the trick. I have used NEW_ID to get completely random name of databases.

declare @number_of_databases int, @loop int
select @number_of_databases = 10
select @loop = 1
declare @random_name varchar(40)
declare @str nvarchar(100)

while (@number_of_databases >= @loop)
begin
select @str = N'Create database [' + convert(varchar(100),NEWID())  +N']'
exec sp_executesql @str
set @loop=@loop+1
end

Once the script if executed, I have below in my management studio. Your databases would definitely be different.

image

Now, my task is – drop those databases which are created today. Without knowing the trick, one would get all databases name by query and then right click on database, choose delete. That would open a new window and we would choose “close existing connection..” and again hit OK. This has to be done 10 times. Now, here is my way of doing it.

Click F7 on keyboard when SSMS is open. This would open “Object Explorer Details”. You can also use “View” in menu bar and choose “Object Explorer Details” item there. This would open a interface which is “details” on the object selected in “Object Explorer” . I would refer this as OED in later part of the blog. (OE of left and OED on right)

image

In OED, we have capability to sort the item based on various columns available. I want to sort databases them using date created. But by default that column is not shown. Let’s Right click on column header in OED and choose the column which we are interested. I have selected “Date Created”

image

Once that’s done, I can choose the position of the column by “dragging” the column name

image

Now, we can SORT as well by clicking on column name. I have sorted them by date created and as we can see all databases which I have created by script have listed next to each other. OED has capability the select multiple objects. This can be done by:

  • Use Shift key to choose all objects next to each other.
  • Use Ctrl key to choose multiple object using mouse

Once desired objects are selected, use right click and choose delete. Simple. huh?

image

And once we choose delete, we get “Delete Objects” dialogue box which is similar to single delete.

image

We can choose the desired option and hit OK.

Same operation would work for tables as well. We just need to choose proper node on “Object Explorer” and get details under “Object Explorer Details” – OED

image

Again, choose multiple tables in OED, right click and delete.

I always felt that SQL Server Management Studio is one of “unexplored” and “underestimated” tool in SQL Server Product. Hope this blog has shown a little “hidden” gem of SSMS. If you know any such trick, please use comment section to share your knowledge.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in SQL Server Management Studio, SSMS | Tagged: , , , , , , , | 1 Comment »

    Help : Getting error “Unable to create a restore plan due to break in the LSN chain”

    Posted by blakhani on May 29, 2014


    “All characters appearing in this blog are fictitious. Any resemblance to real persons, living or dead, is purely coincidental… except me”

    <Tring…Tring>
    Peter: Hello Balmukund
    Me: Hey Peter. How are you?
    Peter: Not so good. Having some trouble with a critical server.
    Me: Yeah, I knew that you would call me when there is an issue with critical server. <laugh> Go ahead and explain me the issue.
    Peter: I am not able to restore the transaction log backup and getting error “Unable to create a restore plan due to break in the LSN chain”

    Me: Wow. Never heard of “restore plan” error. hang on a second.. let me open my laptop.
    Peter: Sure.
    Me: Okay. What was the error again? unable.. restore plan..?
    Peter: Unable to create a restore plan due to break in the LSN chain.
    Me: Well, interestingly, I don’t see that error in sys.messages table in SQL Server Instance.
    Peter: but it coming in SQL Server.
    Me: Where exactly you are seeing this error? Tell me exact steps.
    Peter: I am seeing that error in Management Studio. I am using SQL Server 2012 Instance and SQL Server 2012 management studio to restore backups. I have restored one full backup and now want to restore next log backup.
    Me: And there is no real break in the chain?
    Peter: Yes. I have taken them manually, one after another.
    Me: Okay. Would you mind sending me screenshot and complete error via email. I am on my laptop right now. Let’s fix it right away.
    Peter: Sure. <1 min silence> Sent.
    Me. Okay. Let me received it and meantime I am searching. <30 second silence>  Okay. Got the email.

    image

    Unable to create restore plan due to break in the LSN chain. (Microsoft.SqlServer.SmoExtended)
    ——————————
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.3000.0+((SQL11_PCU_Main).121019-1325+)&LinkId=20476
    ——————————
    Program Location:
       at Microsoft.SqlServer.Management.Smo.DatabaseRestorePlanner.SelectBackupSetsForPlan(RestorePlan plan)
       at Microsoft.SqlServer.Management.Smo.DatabaseRestorePlanner.CreateRestorePlan(RestoreOptions ro)
       at Microsoft.SqlServer.Management.RelationalEngineTasks.RestoreDatabaseDialogController.<>c__DisplayClass2.<CreateRestorePlan>b__1(IBackgroundOperationContext backgroundContext)

    Me: Okay. that’s SMO error and that’s why I don’t see it in sys.messages. It is failing while creating restore plan to show in UI.
    Peter: Aha. So, what should I do.
    Me: T-SQL would work for sure. can you use “Restore log from disk = ‘Path’ command?
    Peter: Ahem.. any other way.. You know how much T-SQL.
    Me: Let me see. <1 min silence> I believe you have used “restore database” UI? Correct?
    Peter: Yes.
    Me: Okay. I can see that this is an issue filed in SQL 2012 management studio. (reference)
    Peter: Is it fixed?
    Me: Yeah, fixed in SQL 2014 Management studio already.
    Peter: So what should I do?
    Me: You have many options now.
    1) Use SQL 2014 SSMS
    2) Use “restore files and filegroups”

    image

    3) Use different restore option in UI

    image

    4) Drop the database and restore both backups together (full and log) in same UI. Haven’t you heard of recovery advisor? I will send you link later.
    5) and last option, which you won’t like is T-SQL.

    Peter: Wow. So many solutions to one simple problem. You are a Gem!
    Me: You are so kind. Thanks.
    Peter: Okay. Let me do restore now. My manager is pinging me to fix this ASAP.
    Me: Sure. Talk to you later. Bye.
    Peter: Bye

    Like the story? Make a comment.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in SQL Server | Tagged: , , , , | Leave a Comment »