Complex SQL Server Database Query -


previously had 1 table (i have more, ofc, these ones i'm struggling with), university table.

i want create 2 more tables : state , city.

table attributes

university: id, name, shortname, fk_state, fk_city  state: id, name, shortname  city : id, name 

problem

i parsing excel sheet universities (including city , state in university resides). once have information in memory, hardest part comes.

how i:

insert universities in database,including state , city, querying state , city databases ids, set fk's of university correctly.

example:
once add university named 'puc-rio', presented in 'rio de janeiro', (city) 'rio de janeiro' (state aswell). adding university not problem, but, how can update foreign key 'rio de janeiro' key on state , city tables?

you'll have each university:

insert university (..., fk_city, fk_state) values (..., (select id city name = @city), (select id state name = @state)) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -