How can I programmatically check (parse) the validity of a TSQL statement?

后端 未结 7 436
礼貌的吻别
礼貌的吻别 2020-12-04 10:25

I\'m trying to make my integration tests more idempotent. One idea was to execute rollback after every test, the other idea was to some how programatically parse the text,

相关标签:
7条回答
  • 2020-12-04 10:59

    +1 to Eric's answer. But I've found SET FMTONLY ON to also be useful as SET NOEXEC ON doesn't appear to throw up all errors.

    e.g.

    SELECT * FROM ATableThatDoesNotExist
    

    Running that with SET NOEXEC ON says it was successful, despite the table not existing in the database. Running it with SET FMTONLY ON instead, will throw the "Invalid object name" error.

    SET FMTONLY ON also returns metadata about the resultset that would be returned, which can come in very handy

    0 讨论(0)
提交回复
热议问题