Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I would like to know what is the syntax to move existing data from one table to another, for example tblAsset which contains Policy No (INT), PolicyStart(DateTime) and PolicyEnd(DateTime) Fields, I would like to refine this table and place this data in a new table of its own, e.g. tblPolicyInfo within the database.

What would the syntax be to move the fields from the tblAsset to tblPolicyInfo? I will require a FK to ensure that the data remains relational so that the data is linked to the correct record. The tblAsset PrimaryKey is AssetID and the new table tblPolicyInfo will be using the PolicyID as its primary key. Correct me if I'm wrong but the best way to link these two tables together would be to have an AssetID FK in the tblPolicyInfo Table. I'd obviously need to copy across the AssetID into the FK AssetID to ensure they remain relational, so that the data is linked to the correct record?

share|improve this question
Which DBMS are you using? – swasheck Jun 17 '12 at 22:42
1  
This is pretty basic regardless of the DBMS and may therefore be off topic. – Leigh Riffel Jun 18 '12 at 13:55
Really basic syntax is off-topic here. It would be a fit on Stack Overflow but also a dupe there. – JNK Jun 18 '12 at 15:11

closed as off topic by Leigh Riffel, JNK Jun 18 '12 at 15:11

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

Write a SELECT statement that generates the rows in the form required in the destination table, then prepend it with INSERT INTO $DESTINATION_TABLE ($COL1, $COL2, ... $COLn).

share|improve this answer
insert into tblPolicyInfo (PolicyNo, PolicyStart, PolicyEnd)
select PolicyNo, PolicyStart, PolicyEnd from tblAsset
where ...
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.