What is the T-SQL to normalize an existing table?

I'd like to convert an existing table into the 1st normal form (simplest normalization possible; see the example).

Do you happen to know what is the T-SQL is for this sort of problem? Many thanks!

enter image description here

Update

Tried the answer below, it worked perfectly. Here is the steps I used to test the answer:

  1. Start up Microsoft SQL Management Studio.
  2. Create the tables, with the data below.
  3. Make sure that the ID in "Customer" is set to "Primary Key", and "identity".
  4. Make sure that the ID in "Order" has no special settings (its a foreign key).
  5. Open up a database diagram, then create a 1:* relationship between the "Customer" and "Order" tables.
  6. Execute the script on the "Customer" table and the "Order" table, it will automatically normalize the data properly for you.
  7. This is very useful if you are starting from a flat .csv file that has just been imported, and you want to copy the information into a normalized form in the database.
5
задан Contango 13 February 2011 в 18:46
поделиться