次のSQLを実行しようとしています:
declare @newLine as varchar(1) = char(13);
declare @sqlCmd as varchar(max) = '';
SELECT @sqlCmd = @sqlCmd + 'alter table ' + OBJECT_NAME(parent_object_id) + ' drop constraint ' + OBJECT_NAME(OBJECT_ID) + ';' + @newLine
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
order by case when left(OBJECT_NAME(OBJECT_ID),2) = 'PK' then 1 else 0 end
exec (@sqlCmd)
ただし、これにより次のエラーメッセージが表示されます。
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
メッセージが表示される理由について、誰かアドバイスをいただけませんか。私が知る限り、このスクリプトは以前は機能していましたが、現在は機能していません。
選択が文字列に入っていない場合の出力は次のようになります。
alter table Answer drop constraint FK_dbo.Answer_dbo.Question_QuestionId;
alter table Question drop constraint FK_dbo.Question_dbo.Problem_ProblemId;
alter table Question drop constraint FK_dbo.Question_dbo.QuestionStatus_QuestionStatusId;
alter table Problem drop constraint FK_dbo.Problem_dbo.Reference_ReferenceId;
作成に使用したコードは次のとおりです。
ALTER TABLE [dbo].[Answer] WITH CHECK ADD CONSTRAINT [FK_dbo.Answer_dbo.Question_QuestionId] FOREIGN KEY([QuestionId])
REFERENCES [dbo].[Question] ([QuestionId])