General discussion

Locked

Need Help with SQL

By dksmith ·
I am a new SQL and need some help.

I have two tables in two databases. I need to pull six fields from table A and insert them into table B (can do that -- Insert Into).

My limitation is when Table B has seven fields because the table has a default primary key field of ID (int). When I copy over the six fields from A into B, I need the ID field to be given a unique (preferably sequential) int value and the additional six values to fall into place.

insert into 'TABLE B' SELECT Field1, Field2, Field3, Field4, Field5, Field6 FROM 'Table A'

What do I do with the ID field that needs to be unique?

Any suggestions?

email me with questions at davidksmith@hotmail.com
thanks.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

each table has unique ID or just B?

by John Wilker In reply to Need Help with SQL

Do both tables have Unique IDs or just Table B?

If Table B has a Unique ID field with IDENTITY. it will increment as data is inserted. so as the insert into statement executes each new row going into B should get a new sequential ID. Does Table B's ID column have IDentity? in Ent man you can see if it does.

HTH, feel free to email me if that made no sense :)
john@red-omega.com

Collapse -

by joshayoung In reply to Need Help with SQL

dksmit -

Based on your message board posting, I wanted to introduce myself to help in this or other matters that may from time to time present themselves.

I am a business process and information project management specialist who spent over ten years with big "five" accounting firms learning to apply nearly all popular database and ERP type applications. I am now an independent consultant with my own practice and a small support staff - I leverage most of my work to dedicated third party developers for which I am the general contractor (a la a real estate development project.) the description of your need sounds relatively easy to quantify and to provide a solution given your short and long-range objectives. I would be happy to helpvia a return email or perhaps we could begin a relationship that might benefit your business now or in the future. My advantage is in my extensive project mananagment as well as my hands-on database development, integration and analysis skill in single user to scalable enterprise database systems. I offer extraordinarily competitive rates and have extensive experience with both very small and very large (fortune 500) clients. I am based in LA but travel extensively. my text/numeric/operatorasst pager is 800.494.3205 and my email address is joshayoung@yahoo.com if you wish to discuss. In either event, i wish you the best in your business.

- Josh Young
Hermosa Beach, CA

Collapse -

Use a sequence

by blarman In reply to Need Help with SQL

Set up a sequence for the primary key field in table B. Then use sequence.nextval to supply the value as it gets inserted.

It works.

Collapse -

here's how

by sunnythegeek In reply to Need Help with SQL

create table B as select f1,f2,f3,f4,f5,f6 from A;

Back to Software Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums