
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Can we insert records in a MySQL table without auto_increment values?
- How can I insert the values in columns without specifying the names of the column in MySQL INSERT INTO statement?
- 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 we specify default values in MySQL INSERT statement?
- How can we create MySQL views without any column list?
- How can we insert current date automatically in a column of MySQL table?
- Why can't we use column name “desc” in MySQL?
- Can we use reserved word ‘index’ as MySQL column name?
- Can we insert null values in a Java list?
- How to insert own values into auto_increment column in MySQL?
- How can we insert current year automatically in a YEAR type column of MySQL table?
- Can we use MySQL keyword as alias name for a column?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- Can we implement nested insert with select in MySQL?

Advertisements