私は以前、正常に機能する次のスクリプトを使用しました。
public const string application =
@"SET IDENTITY_INSERT Application ON
INSERT INTO Application(ApplicationId, Name, ModifiedDate) VALUES (1, 'x', getdate() );
INSERT INTO Application(ApplicationId, Name, ModifiedDate) VALUES (2, 'y', getdate() );
INSERT INTO Application(ApplicationId, Name, ModifiedDate) VALUES (3, 'z', getdate() );
SET IDENTITY_INSERT Application OFF
DBCC CHECKIDENT( 'Application', RESEED )";
DDLを実行したいのですが、エラーメッセージが表示されます。
public const string dropCreate =
@"
GO
ALTER TABLE [dbo].[TestAccount] DROP CONSTRAINT [TestAccount_Application]
GO
DROP TABLE [dbo].[TestAccount]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestAccount](
[TestAccountId] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](35) NOT NULL,
[ApplicationId] [int] NOT NULL,
[RowVersion] [timestamp] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED
(
[TestAccountId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TestAccount] WITH CHECK ADD CONSTRAINT [TestAccount_Application] FOREIGN KEY([ApplicationId])
REFERENCES [dbo].[Application] ([ApplicationId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TestAccount] CHECK CONSTRAINT [TestAccount_Application]
GO";
}
HResult=-2146232060
Message=Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
C#からDDLを実行することは可能ですか?私が使用しているコードは次のようになります。
context.Database.ExecuteSqlCommand(TestAccountSQL.dropCreate);