Oracle Performance – Sequences vs Count for Auto-Increment

oracleperformancequery-performancesequence

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

Best Answer

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.