Can we insert records in a MySQL table without auto_increment values?

MySQLMySQLi Database

Yes, we can insert without the auto_increment since it gets inserted on its own. Let us first create a table −

mysql> create table DemoTable1479
   -> (
   -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> EmployeeSalary int
   -> );
Query OK, 0 rows affected (0.86 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1479(EmployeeSalary) values(6800);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1479(EmployeeSalary) values(5600);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable1479(EmployeeSalary) values(5700);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1479(EmployeeSalary) values(6900);
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1479(EmployeeSalary) values(15000);
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1479;

This will produce the following output −

+------------+----------------+
| EmployeeId | EmployeeSalary |
+------------+----------------+
|          1 |           6800 |
|          2 |           5600 |
|          3 |           5700 |
|          4 |           6900 |
|          5 |          15000 |
+------------+----------------+
5 rows in set (0.00 sec)
raja
Published on 10-Dec-2019 07:59:13
Advertisements