|
Posted by Hamilton sucks on 09/08/07 17:34
On Sep 7, 6:08 pm, "David Portas"
<REMOVE_BEFORE_REPLYING_dpor...@acm.org> wrote:
> "Hamilton sucks" <c...@mcmaster.ca> wrote in message
>
> news:1189201676.191048.77380@22g2000hsm.googlegroups.com...
>
> > Hi:
> > I need to add some records in a table called location(primary key:
> > loc_id). What I want to do is for each location in the table, I add
> > the same record but with a different loc_id, which can be a random
> > string. All the other column should contain the same value. Can anyone
> > give me a hint on how to do this in SQL server 2000 enterprise
> > manager?
> > thx.
>
> A strange design. If the only key is random then how do you hope to retrieve
> the information? If the rest of the data is to be identical then why bother
> copying it?
>
> DECLARE @loc_id VARCHAR(36);
> SET @loc_id = CAST(NEWID() AS VARCHAR(36));
>
> INSERT INTO location (@loc_id, col1, col2, ...)
> SELECT col1, col2, ...
> FROM location ;
>
> --
> David Portas
Thanks, david for your help. The reason for copying records is that I
need to change them to new records, which are exactly the same as the
old records except one column value. The loc_id is the primary key but
it's not really used for searching information. So basically I don't
care about the loc_id as long as they are unique, that 's why i want
it to be random.
Navigation:
[Reply to this message]
|