I'm working with an application that keeps a list of clients:

  CREATE TABLE clients (
    id integer primary key,
    fingerprint varchar (40) unique,
    ...
  );

Clients are uniquely identified by fingerprint but are referenced
by an integer id in most places in the database.

Clients can be referred to by one or more names and so there's
another table:

  CREATE TABLE client_names (
    id integer,
    name text
  );

Names aren't unique. Two clients can have the same name.

Essentially what I'm trying to do is atomically add a new
name for a client but only if a given id isn't
already associated with that name. In other words, "do both
the given client id and name appear in the same row anywhere
in the client_names table?". Can't make the 'name' column
'unique' as two clients may have the same name. Can't make
the 'id' column 'unique' as a client may have more than one
name...

What is the recommended way to do this with SQLite?

PS: I'm not wrong in thinking that IF EXISTS (...) THEN ...
isn't implemented, am I? I couldn't get the sqlite3 interpreter
to accept any statements of that form ("syntax error near IF").
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to