
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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)
Advertisements