0

I have a table with the following fields

id - (int) primary
project_id - (int)
post_id - (int)

I need to set it so that the post_id field is unique but only on a specific project id.

ie:

id || project_id || post_id

1     1             1
2     1             2
3     1             3
4     2             1
5     2             2
6     2             3

is this possible?

EDIT: I now have a new problem, sometimes the post_id field will be null, is there a way of using

      ALTER TABLE TableName
      ADD CONSTRAINT uc_PostProject UNIQUE (post_id,project_id)

But ignore null post_id's?

4

1 回答 1

0

添加以下内容

ALTER TABLE TableName
ADD CONSTRAINT uc_PostProject UNIQUE (post_id,project_id)

有关详细信息,请参阅http://www.w3schools.com/sql/sql_unique.asp

于 2013-07-12T09:55:54.093 回答