vendredi 31 juillet 2015

Split Table Into Two Separate Tables and Set New Primary Key as a Foreign Key

I have seen posts similar to what I need, but they all fall slightly short. I'm also not sure if what I need can be done. If it cannot be done, then any suggestions would be greatly appreciated.

I am reconstructing my database, and need to merge parts of three different tables into one. Currently I have three different types of tasks, let's call them DailyTasks, Reviews and Requests. All three tables have similar fields such as DateCreated, DateCompleted, EstimatedHours etc. I have created a parent table, called Tasks, which contains these common fields, and the other tables (DailyTasks, Reviews and Requests) only have fields that are specific to themselves. The child tables now also have a Foreign Key, TaskID, that points to the parent table. I believe this is standard database practice, correct me if I'm wrong.

Currently I am working in a test database, so I can pull the original data from the live database for testing purposes. I need to be able to pull the common fields from each table and place them in the parent table, while at the same time placing the new primary key into the TaskID column of the child table.

I would have like to of have used a join, but I don't believe I can insert into two tables that way while retrieving the Primary Key. My next thought if a join won't work is to use a cursor. Any help would be appreciated and I hope I've explained everything properly.

EDIT Here are the table's fields

TASKS (Parent)

  • TaskID (PK)
  • DateCreated
  • DateCompleted
  • DateDue
  • EstHrs
  • BaselineHrs
  • Notes
  • Priority
  • CreatedBy

DailyTasks (Child)

  • EngTaskID (PK)
  • TaskID (FK)
  • ProjectID
  • Description
  • AssignedTo

Requests (Child)

  • DrawingRequestID (PK)
  • TaskID (FK)
  • DrawingLink
  • PartNumber

Reviews (Child)

  • JobAuditID (PK)
  • TaskID (FK)
  • ItemNumber
  • CycleTime
  • ToolingRequirements

Aucun commentaire:

Enregistrer un commentaire