views:

18

answers:

1

Hello everybody,

I have a question about DB modeling, I have a table created as following:

CREATE TABLE "users_articles" ("id" INTEGER PRIMARY KEY  NOT NULL,"article_id" INTEGER,"user_id" INTEGER)
  1. Which statement will alter this table, so that the combination of article_id and user_id is unique?
  2. Which statement tells me, if the DB has already been altered?

Thanks,

Markus

+1  A: 
  1. You need to create unique index:

    CREATE UNIQUE INDEX unique_users_articles ON users_articles (article_id, user_id)

  2. Please clarify why you need it?
    UPDATE: Use IF NOT EXISTS to ignore index creation if it already exists:

    CREATE UNIQUE INDEX IF NOT EXISTS unique_users_articles ON users_articles (article_id, user_id)

cement
Thanks for the solution for my first Question! The second: As I make a update on a mobile application I need to prove whether the locale db already has gotten this change on unique index.
Markus
I've updated my answer.
cement
Perfect! Thanks a lot! That was exactly what I was looking for!
Markus