sql server - SQL Insert - Only insert on this condition -
i have table 1
:
id userstring date ------------------------- 1 krbs 4/25/2014 2 wefg 4/24/2014
and table 2
:
id userstring + other user info ---------------------------------- 1 krbs + . . .. .
i'm preforming insert table 1 make condition insert if user available in table 2 (only insert row in table 1 if user exist in table2)
i'm doing 2 separate sql checks (one if user exist insert) i'm sure there better way
best way achieve define foreign key
on table. simplest , implicit way it, reference on can found on msdn. means not ever able a) insert entry table if no corresponding fk exists, , b) delete base table if entries foreign key here (in case, delete user if has settings ). like:
alter table nameofthetable add constraint fk_somenameforthekey foreign key (nameofcolfromthistable) references nameoftheothertable (nameofthecolumnyouarereferencing);
Comments
Post a Comment