tags:

views:

33

answers:

2

I have an issue in mysql that i have a field id which is auto increment and some other fields. where the id field should not be autoincremented while enterting the null values and should be autoincremented while entering values insert values in the same row while giving not null values .

+1  A: 

It sounds like you need to generate the value for the id field yourself, in your own code, rather than having the database generate it.

If you create an identity field in the database, the database will create the field automatically. Generally this occurs when the record is saved, whether there are null fields present or not. If you need more control than this, you have to generate the id values yourself.

If you need to know what the next id number is, you can get it with SELECT MAX(id_field);

Robert Harvey
If you use MAX(id), be wary that if you delete rows then an id may be reused.
A: 

Robert Harvey's answer tackles the problem but I would also suggest looking at what you are saving and see if there is another approach. Perhaps the null values should be saved in another table? Perhaps the column you have as auto-increment isn't the primary key.

This may not be the direction but in this case it's worth stepping back and re-examining.

Paulo