Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nbourre
Starting Member
14 Posts |
Posted - 2006-12-29 : 17:08:59
|
Hi,I am working on a non-relational Filemaker DB (FM) (A mess!) and I'm developping a new relationnal DB in SQL Server so I can transfert the whole Filemaker DB on SQL Server. I know how to develop a database, but I'm unfamiliar with stored procedure.Here is one of my problem. I imported a table from FM which was not normalized. I created some normalized tables, now I want to fill these tables with the unormalized one. How can I do this with stored procedure?By Example:- An non-normalized person table has a province field which is a text field.
- I normalized the table by creating a Province table with two fields pkProvinceID (Identification) and ProvinceName.
- I created a relation between the Person and Province tables. Joined by pkProvinceID and fkProvinceID
The question is how do I fill the fkProvinceID in the person table with the right province?I presume that the algorithm should be like this:UPDATE PersonSET fkProvinceID = ( SELECT pkProvinceID FROM Province WHERE Person.Province = Province.ProvinceName)WHERE fkProvinceID = NULLAny help would be great!Thank youNickBeginning with something is a good start! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-12-29 : 17:28:07
|
| UPDATE peSET ProvinceID = pr.ProvinceIDFROM Person peINNER JOIN Province prON pe.ProvinceID = pr.ProvinceIDYou should reconsider adding pk and fk to your column names. It is apparent which one is which in a query when you use aliases.Tara Kizer |
 |
|
|
|
|
|