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
Post a Comment