HI,
I am new to mysql i want to know why mysql have autoincrement with keys..

Is their possible to declare only auto increment to a column.

Good Question, Any sql will be having only one primary key for one table, if you want to make another keys, you can add unique keys to the columns and you can make it as a primary(with 2 or more columns).

If we use auto_increment in MySQL, it assumes the column as a Primary Key and asks us to add Primary Key to that column.

Hi,
Thanks for u r response.

when we declare a column as auto increment in a table. Sql requier to specify a primary key or any key for that column.If i not specify a key for auto increment an error message gets appeared.

Y this error happens in sql.Can u explain it.

Thanks once again.
prem..

The 'key' is there to 'unlock' all other fields in the table. It 'auto increments' with a 'unique id' so that records are kept separate and tidy and so that you can access and refer to and update specific records.

Hi,
Thanks for u r response.

a key or primary key is required for anything that is 'auto incremented'
so you can 'unlock' the rest of the table. The field should be called
something like "table_id" and use "auto increment" and be "primary key"
or you will get errors for sure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.