

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Avoiding rewrite attributes with MySQL AUTO_INCREMENT
You can avoid with the help of providing the value (NULL,0,DEFAULT) with AUTO_INCREMENT. Let us first create a table −
mysql> create table DemoTable1350 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.44 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1350 values(NULL,'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1350 values(0,'Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1350 values(DEFAULT,'Chris'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1350;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Chris | | 3 | Chris | +-----------+-------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Set custom Auto Increment with ZEROFILL in MySQL
- Change the Auto Increment counter in MySQL?
- Passing NULL to MySQL for auto increment?
- Two columns as primary key with auto-increment in MySQL?
- How to change auto increment number in MySQL?
- How to make MySQL table primary key auto increment?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to create a table with auto-increment column in MySQL using JDBC?
- How to auto increment with 1 after deleting data from a MySQL table?
- How to get the next auto-increment id in MySQL?
- How to set initial value and auto increment in MySQL?
- How to change auto increment number in the beginning in MySQL?
- Changing the current count of an Auto Increment value in MySQL?
- How to handle fragmentation of auto increment ID column in MySQL?
- Set auto increment initial value for MySQL table using ALTER command
Advertisements