If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Extracting data from large SINGLE-table database to MULT-table relational database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-06, 11:11
lbfrank lbfrank is offline
Registered User
 
Join Date: Oct 2006
Posts: 1
Extracting data from large SINGLE-table database to MULT-table relational database

Hi All.

I have a very large single-table database of articles that I want to convert to a multi-table, relational database.

The existing single-table database contains fields for article author, article source, and article category, where several 'author', 'source', and 'category' IDs repeat dozens of times for hundreds of different articles.

I want to create seperate tables for author, source, and category and populate the new tables by extracting data from the original single-table database by unique ID field.

I figured out how to use INSERT and SELECT to pull data in new tables, but can't figure out how to pull only a single instance of a unique author, source, and category to create master reference tables for author/source/category.

Any assistance would be much appreciated.

Thanks in advance.

L.B.
lbfrank@envoyoffice.com
Reply With Quote
  #2 (permalink)  
Old 10-10-06, 12:41
sideral sideral is offline
Registered User
 
Join Date: Oct 2006
Posts: 2
Maybe try this:
-- This creates the table
CREATE TABLE author(
author_id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(50) NOT NULL
)

-- This inserts all the existing author, only once
INSERT INTO author ( name)
SELECT DISTINCT author_name FROM articles

-- This creates a column in articles table to hold the recently generated author_id

ALTER TABLE articles ADD author_id int NULL

-- Add the author_id in articles table

UPDATE articles
INNER JOIN author ON articles.author_name = author.name
SET articles.author_id = author.author_id

-- You may want to ensure that all worked well, and do a backup before this last step

ALTER TABLE articles DROP author_name

Repeat this steps for source and category as well. Hope this helps!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On