4 votes

Fortnightly Programming Q&A Thread

General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.

Don't forget to format your code using the triple backticks or tildes:

Here is my schema:

```sql
CREATE TABLE article_to_warehouse (
  article_id   INTEGER
, warehouse_id INTEGER
)
;
```

How do I add a `UNIQUE` constraint?

3 comments

  1. [3]
    Rudism
    Link
    Instead of a UNIQUE constraint I'd just make a multi-column primary key, which would achieve the same result. In postgresql it would look like this: create table article_to_warehouse ( article_id...

    Instead of a UNIQUE constraint I'd just make a multi-column primary key, which would achieve the same result. In postgresql it would look like this:

    create table article_to_warehouse (
      article_id integer,
      warehouse_id integer,
      primary key (article_id, warehouse_id)
    );
    
    2 votes
    1. [2]
      archevel
      Link Parent
      Just as an FYI; this is a recurring thread that contains the question as an example in each post. The question is there to illustrate the format to use for posting questions.

      Just as an FYI; this is a recurring thread that contains the question as an example in each post. The question is there to illustrate the format to use for posting questions.

      1 vote
      1. Rudism
        Link Parent
        I realized that was probably the case as I was typing, but figured I've already come this far and the thread is empty anyway, might as well commit to it.

        I realized that was probably the case as I was typing, but figured I've already come this far and the thread is empty anyway, might as well commit to it.

        4 votes