home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 19,203 of 19,505   
   Erland Sommarskog to jess.rgm@gmail.com   
   Re: WHILE LOOP AS FOR LOOP   
   29 Jul 15 15:44:21   
   
   From: esquel@sommarskog.se   
      
   Jessica González (jess.rgm@gmail.com) writes:   
   > thanks.. but   
   >   
   > SET IDENTITY_INSERT table ON;   
   > INSERT INTO table(pk,activo,permiso,rol)   
   >       SELECT IDENT_CURRENT('table')+1,'S',id, 1   
   >       FROM table2   
   >   
   >   
   > return error   
   >   
   > Violation of PRIMARY KEY constraint 'PK__table__3213E83F2B947552'.   
   > Cannot insert duplicate key in object 'table'. The duplicate key value   
   > is (6).   
      
   Why do you fiddle with IDENTITY_INSERT ON? That is an option you rarely have   
   any reason to play with. And IDENT_CURRENT you have even more rare reason to   
   touch. That is not a particularly useful function.   
      
   If you have made the column an IDENTITY column, you should not assign the   
   values explicitly. And vice versa: if you want to be able to specify the   
   values explicitly, you sould not use IDENTITY.   
      
      
   --   
   Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se   
      
   Books Online for SQL Server 2005 at   
   http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx   
   Books Online for SQL Server 2000 at   
   http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca