3

I'm trying to create the following check constraint.

(
   [Href] IS NOT NULL AND
   [ETag] IS NOT NULL AND
   [UserName] IS NOT NULL AND
   [Password] IS NOT NULL AND
   [UID] IS NOT NULL
)
OR
(
   [Href] IS NULL AND
   [ETag] IS NULL AND
   [UserName] IS NULL AND
   [Password] IS NULL AND
   [UID] IS NULL
)

I can save it and there are no errors. But SSMS removes both of the inner parentheses (such that there is only the opening parenthesis at the start and the closing parenthesis at the end).

This would seem to change the meaning entirely. I want either all of these columns to be null or none of them to be null. Is there a reason why SQL Server can't handle this?

4

1 に答える 1

8

SSMSは正しいです。括弧は必要ありません。

ANDは SQL よりも優先順位が高いORため、括弧の有無にかかわらず 2 つのバージョンは同等です。

于 2012-07-31T00:32:23.323 に答える