SQL Create a New Table with Data from an Existing Table
Every have one of those situations where you realize, oops, you didn’t optimize that database schema as well as you should have? (Read, not enough information provided at project start-up.) I needed to copy some information out of my main Contacts table and put it into it’s own table. Google to the rescue.
Here’s what I used, in case I need it again.
CREATE TABLE VolunteerInfo SELECT ContactID, WhyVolunteer, Availability, AddNotes, VTaskID, VolunteerWith, OtherTask, DateCreated, CreatedByID, DateModified, ModifiedByID FROM Contacts WHERE WhyVolunteer <> '' or Availability <> '' or AddNotes <> '' or VTaskID <> '' or VolunteerWith <> ''
228 records created, add an auto-increment Primary Key for my new table, and humming along to something else.
Note: To make an existing field an auto-increment Primary Key, you must first make the field a Primary Key, then make it an Auto Increment. Must be done in two steps.
