Business Key Generation
am 05.02.2010 18:37:03 von Tom Goring
--000e0cdf70e24f682e047edde665
Content-Type: text/plain; charset=UTF-8
Hi,
I have a table that I need to migrate some data into:
CREATE TABLE `employee` (
`employeeid` bigint(20) NOT NULL auto_increment,
...
`reference` varchar(20) default NULL,
`fkcompanyid` bigint(20) default NULL,
PRIMARY KEY (`employeeid`),
KEY `FK4722E6AE82D7E095` (`fkcompanyid`),
CONSTRAINT `FK4722E6AE82D7E095` FOREIGN KEY (`fkcompanyid`) REFERENCES
`company` (`companyid`),
....
) ENGINE=InnoDB AUTO_INCREMENT=1000000000001585 DEFAULT CHARSET=latin1 |
My question is I want to generate a reference business key (a number) as the
migrated data is blank.
something like
update employee set reference = ROWNUM where fkcompanyid = X
I think in Oracle ROWNUM would help me do this.
I.e. generate a reference based on the position in the result set.
any Ideas ?
--
Tom Goring
--000e0cdf70e24f682e047edde665--
RE: Business Key Generation
am 05.02.2010 19:18:34 von Gavin Towey
WW91ciBhdXRvLWluY3JlbWVudCBjb3VsZCBiZSBlZmZlY3RpdmVseSBhIHJv dyBudW1iZXIuIE90
aGVyd2lzZSB0aGVyZSBpcyB0aGlzIHRlY2huaXF1ZSB3aXRoIHVzZXIgdmFy aWFibGVzOg0KDQpT
RVQgQHJvd251bSA6PSAwOw0KU0VMRUNUIEByb3dudW06PUByb3dudW0rMSBh cyBST1dOVU0sIC4u
LiBGUk9NIC4uLiA7DQoNClJlZ2FyZHMsDQpHYXZpbiBUb3dleQ0KDQoNCi0t LS0tT3JpZ2luYWwg
TWVzc2FnZS0tLS0tDQpGcm9tOiBUb20gR29yaW5nIFttYWlsdG86dG9tLmdv cmluZ0BnbWFpbC5j
b21dDQpTZW50OiBGcmlkYXksIEZlYnJ1YXJ5IDA1LCAyMDEwIDk6MzcgQU0N ClRvOiBteXNxbEBs
aXN0cy5teXNxbC5jb20NClN1YmplY3Q6IEJ1c2luZXNzIEtleSBHZW5lcmF0 aW9uDQoNCkhpLA0K
DQpJIGhhdmUgYSB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