implement SQL Sequence (fix ID generation bug)