Subject | help with insert |
---|---|
Author | Sergio H. Gonzalez |
Post date | 2010-11-30T20:10:15Z |
Hello ! I have a database which can manage multiple enterprises, so in all the
databse's table I have an ID_ENTERPRISE field.
I'm trying to do a tool in order to allow the user copy some table for one
enterprise to other. For example if I have this article's table:
ID_ENTERPRISE ID_ARTICLE DESCRIPTION
=======================================
1 1 MONITOR
1 2 MOUSE
1 3 KEYBOARD
I'd like to generate a new table:
ID_ENTERPRISE ID_ARTICLE DESCRIPTION
=======================================
2 4 MONITOR
2 5 MOUSE
2 6 KEYBOARD
ID_ARTICLE is the PK, so I can't repeat that values. I could do it with a SP or
in the client side. No problem with that. But I wonder if there is a more
efficient way to do it... something like :
insert into articles (select * from articles where id_enterprise = 1) but, of
course, inserting the new enterprise id and new PK from a generator...
I hope I'm clear!!
Thanks!!!
-sergio
databse's table I have an ID_ENTERPRISE field.
I'm trying to do a tool in order to allow the user copy some table for one
enterprise to other. For example if I have this article's table:
ID_ENTERPRISE ID_ARTICLE DESCRIPTION
=======================================
1 1 MONITOR
1 2 MOUSE
1 3 KEYBOARD
I'd like to generate a new table:
ID_ENTERPRISE ID_ARTICLE DESCRIPTION
=======================================
2 4 MONITOR
2 5 MOUSE
2 6 KEYBOARD
ID_ARTICLE is the PK, so I can't repeat that values. I could do it with a SP or
in the client side. No problem with that. But I wonder if there is a more
efficient way to do it... something like :
insert into articles (select * from articles where id_enterprise = 1) but, of
course, inserting the new enterprise id and new PK from a generator...
I hope I'm clear!!
Thanks!!!
-sergio