Vidyalelo
MySQL · Q608

MySQL

Programming · MySQL · question 608

Q608

In MyISAM tables, when a table is emptied with the TRUNCATE TABLE, the counter begins at . . . . . . . .

A.
0
B.
1
Answer
C.
-1
D.
arbitrary

Answer: Option B

Solution

Answer: Option B
Solution:
This question is about how MySQL handles the auto-increment counter in MyISAM tables when you use the `TRUNCATE TABLE` command.

The `TRUNCATE TABLE` command is used to delete all rows from a table.

In MyISAM tables, the auto-increment counter is a special value that helps MySQL assign unique IDs to new rows. When you add a new row, the counter is increased by 1, and the new row gets the current value of the counter.

The question asks what happens to the counter when you use `TRUNCATE TABLE`.

The answer is Option A: 0

When you truncate a table, MySQL resets the auto-increment counter to 0. This ensures that when you start adding new rows again, they will receive unique IDs starting from 1.