[GENERAL] Foreign key check only if not null?

2011-09-12 Thread Phoenix Kiula
Hi, I bet this is a simple solution but I have been racking my brains. I have a column in my table: user_id varchar(100) ; This can be NULL, or it can have a value. If it has a value during INSERT or UPDATE, I want to check that the user exists against my Users table. Otherwise, NULL is

Re: [GENERAL] Foreign key check only if not null?

2011-09-12 Thread Eduardo Piombino
hi, fks do just that. you can create your fk with just one command: alter table xxx add constraint fk_name foreign key (user_id) references users (id); parent table's id field should also be of the same type and also it should be primary key or at least unique. you can create your pk with (if

Re: [GENERAL] Foreign key check only if not null?

2011-09-12 Thread Richard Broersma
On Mon, Sep 12, 2011 at 6:48 PM, Phoenix Kiula phoenix.ki...@gmail.com wrote: I have a column in my table:    user_id  varchar(100) ; This can be NULL, or it can have a value. If it has a value during INSERT or UPDATE, I want to check that the user exists against my Users table. Otherwise,