sql - How do i insert new record in this table? -


i'm sorry noob question.

there're 2 tables: smaller 1 derived bigger one. how insert new record bigger table??

insert people (lname, fname, city, age, salary) values (' doe','john','paris', '25','1000$' ); 

but bigger table contains city number. how should insert 'paris'?? should know number beforehand?? 'paris' isn't in cities (smaller) table!! how records inserted in bigger (people) table??

edit:

added if block check paris.

if not exists (select 1 city city = 'paris') insert city (city) values ('paris')  declare @cid int = (select cityid city city = 'paris')  insert people (lname, fname, city, age, salary)  values (' doe','john', @cid, '25','1000$' ) 

i made assumption structure of city table obviously.

you parameterize @city variable , sub 'paris' everywhere in code.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -