SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Monday, May 22, 2006

Numbering in SQL

SQL Apprentice Question
I have table with 10-20 rows with field P6 which is empty. I want to
update numbers to P6 starting 1 and increasing by 1. I suppose it is
done by triggers but I don't know how to do that

Celko Answers
>> have table with 10-20 rows with field [sic] P6 which is empty [sic]. <<


You have NEVER written SQL before, have you? Columsn are not fields
and we have NULLs, not the empty spreadsheet cells you assume. TOTALLY
WRONG MINDSET!


>> I want to update numbers to P6 starting 1 and increasing by 1. <<


That is a SEQUENTAL MAGNETIC TAPE FILE and you are tryign to write
1950's code in SQL! It has northing whatsoever to do with RDBMS.
Tables have no ordering by definition. This is soooooo wrong

Geeesh!!! You can insert a set at a time, so adding one to a previous
value makes no sense. Doesn't anyone go to RDBMS classes any more?

No comments: