509-261 Cooper Street
Ottawa, Ontario (Canada) K2P 0G3

Michele Foster
(613) 232-7447
michele@wizardev.ca
http://WizarDev.ca/

WizarDev Logo

Professional Web Development, Web Design and Database Solutions

Subscribe to Web Words

Powered by FeedBlitz

RSS Icon Subscribe via RSS

Web Words - Blog

Web Words contains resources useful to web site developers and owners, organized by category and searchable.
Have an item for inclusion here, send it to me.

SQL Create a New Table with Data from an Existing Table

SQL and Database Things

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.

Read SQL COPY TABLE Command

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.

June 18th, 2007

Leave a Reply