
- 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
Can we insert values without mentioning the column name in MySQL?
Yes, we can insert values without mentioning the column name using the following syntax −
insert into yourTableName values(yourValue1,yourValue2,yourValue3,.....N);
Let us first create a table. Here, we have set Id as NOT NULL −
mysql> create table DemoTable862( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) , Age int ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable862 values(NULL,'Chris',23); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable862 values(NULL,'Robert',21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable862 values(NULL,'Mike',24); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable862 values(NULL,'Sam',25); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable862 values(NULL,'Bob',26); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable862;
This will produce the following output. Above, we have set NULL while inserting the values. Since we have set Id as NOT NULL, therefore those NULL values won’t work for Id column and the auto_increment will automatically add values for Id −
+----+-----------+------+ | Id | FirstName | Age | +----+-----------+------+ | 1 | Chris | 23 | | 2 | Robert | 21 | | 3 | Mike | 24 | | 4 | Sam | 25 | | 5 | Bob | 26 | +----+-----------+------+ 5 rows in set (0.00 sec)
- Related Questions & Answers
- Can we insert records in a MySQL table without auto_increment values?
- Can we skip a column name while inserting values in MySQL?
- What MySQL returns on running the INSERT INTO statement without giving the column name and values both?
- How can I insert the values in columns without specifying the names of the column in MySQL INSERT INTO statement?
- How can we specify default values in MySQL INSERT statement?
- How can we create MySQL views without any column list?
- Can we use MySQL keyword as alias name for a column?
- Can we insert null values in a Java list?
- How can we insert current date automatically in a column of MySQL table?
- Can we use reserved word ‘index’ as MySQL column name?
- Why can't we use column name “desc” in MySQL?
- Can we implement nested insert with select in MySQL?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- How can we change the name of a MySQL table?
- How to insert own values into auto_increment column in MySQL?
Advertisements