0

Can some one please tell me the exact difference between the following statements ,

INSERT INTO table1 VALUES ((select count(column-name) from table-name2)+1);

here i am using the count function to auto-increment the value..

The same functionality can be done with sequences..

what will happen when both of this queries are executed and also please tell me the drawbacks of using the count over sequence

  • 5
    The approach using count() is broken and will not work in a multi-user environment (or if you do get it right using table-locks and serialization it won't scale and will be dead-slow) – a_horse_with_no_name Dec 5 '13 at 10:01
1

Count(column_name) will give numbers of not-null records from the table "Table1".

Sequence would return a number irrespective of number of records in the table "Table1" . Sequence can be used globally ,not only specific to a table.

if you require a digit on basic of records in table use Count function. if you require just a running serial number use sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.