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 18,378 of 19,505    |
|    Erland Sommarskog to Gene Wirchenko    |
|    Re: SSE 2008: Referring to Other Rows Be    |
|    13 Jul 11 10:16:57    |
      From: esquel@sommarskog.se              Gene Wirchenko (genew@ocis.net) writes:       > Giving another example, suppose it must be that there are an odd       > number of rows of a type of entry.       >       > create table EvenSteven       > (       > pk varchar(10) not null,       > contrivance int not null       > )       >       > In this case, there must be an odd number of rows for each value       > of contrivance. Suppose we have       > pk contrivance       > A 5       > B 7       > C 6       > D 5       > E 5       > F 5       >       > Adding       > G 6       > H 7       > would be an error (2 6's in total), but adding       > G 6       > H 7       > I 6       > would be fine.       >       > Must I scan through the table and Inserted for each contrivance       > value, or is there a better way?              In this case you will need a trigger. As for how to implement the trigger,       you could assume that the table is OK, and only count the values in inserted       and deleted. But this means that if someone disables the trigger, or       bypasses it with BULK INSERT, that you will never be able to correct the       data again, why it may be better to look at all instances of the values in       the table.                            --       Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se              Links for SQL Server Books Online:       SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx       SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx              --- 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