If you’re a long time IT professional or an occasional user of high or even low tech software you’ll know what I mean when I say “Bugs are not a new thing”.
Some bugs are earth shattering others are an annoyance and some just make you chuckle. Luckily this simple bug is not earth shattering or annoying.
Have you ever scripted an object from SQL Server Management Studio (SSMS)? It does a really good job. You get nice cleanly formatted scripts that start with USE statements to select the database. They even have some simple comments?
Have you ever written a Sequence? Turns out if you script one you’ll notice that Microsoft left you an extra surprise. Double USE statements. Does it matter much? No. Should they fix it? Yes. I noticed this behavior when sequences were first released and it still exists in the latest version of SSMS for SQL 2016 (13.0.1500.23) as of this posting.
To script an object, navigate to it in Object Explorer. Right click and choose any option in the “Script object as” submenu.
Here’s a sample object scripted:
/****** Object: Table [dbo].[appConfig] Script Date: 9/27/2016 9:47:45 PM ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [dbo].[appConfig](
[ConfigType] [varchar](50) NULL,
[ConfigValue] [varchar](50) NULL
) ON [PRIMARY]
SET ANSI_PADDING OFF
Notice the single USE statement at the top?
Now let’s look at a sequence.
/****** Object: Sequence [dbo].[SeqCommodityID] Script Date: 9/27/2016 9:37:37 PM ******/
CREATE SEQUENCE [dbo].[SeqCommodityID]
START WITH 17
INCREMENT BY 1
Two USE statements. Again, this isn’t doing any harm so I can imagine it’s really low on the priority; though, it does seem like an issue that they could fix in about 10 minutes. After two versions, I wonder if they will.