March 20, 2018 at 1:51 pm
Hello :
Trying to understand what i am doing wrong here.
I execute a SQL script to drop an index if it exists and then create it in the same script.
I execute in SSMs and I see the index.
I use the same script in SQL Agent job as a step and i get success result but do not see the index.
What am i doing wrong here?
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].
') AND name = N'index_INDEX')
DROP INDEX [index_INDEX] ON [dbo].[tablename]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tablename') AND name = N'index_INDEX')
CREATE NONCLUSTERED INDEX [index_INDEX] ON [dbo].[tablename]
(
[TAIL_NUMBER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
March 21, 2018 at 12:28 am
dvprao - Tuesday, March 20, 2018 1:51 PMHello :
Trying to understand what i am doing wrong here.
I execute a SQL script to drop an index if it exists and then create it in the same script.
I execute in SSMs and I see the index.
I use the same script in SQL Agent job as a step and i get success result but do not see the index.What am i doing wrong here?
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].') AND name = N'index_INDEX')
DROP INDEX [index_INDEX] ON [dbo].[tablename]
GOSET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GOIF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tablename') AND name = N'index_INDEX')
CREATE NONCLUSTERED INDEX [index_INDEX] ON [dbo].[tablename]
(
[TAIL_NUMBER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
GO is an SSMS specific (configurable) batch delimiter, not recognized in the SQL Agent
😎
March 21, 2018 at 4:23 pm
Thanks for the tip.
I removed all GO lines in the script and for each batch I appended a semi-colon ; to the line.
It seems to have worked.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply