Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Is there a way to name columns in an INSERT statement in MySQL?
Yes, we can name columns in an insert statement. Let us first create a table −
mysql> create table DemoTable674( StudentId int, StudentFirstName varchar(100), StudentLastName varchar(100) ); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable674 set StudentId=10,StudentFirstName='John',StudentLastName='Smith'; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable674 set StudentId=11,StudentFirstName='Carol',StudentLastName='Taylor'; Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable674 set StudentId=12,StudentFirstName='David',StudentLastName='Miller'; Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable674 set StudentId=13,StudentFirstName='Chris',StudentLastName='Brown'; Query OK, 1 row affected (0.53 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable674;
This will produce the following output −
+-----------+------------------+-----------------+ | StudentId | StudentFirstName | StudentLastName | +-----------+------------------+-----------------+ | 10 | John | Smith | | 11 | Carol | Taylor | | 12 | David | Miller | | 13 | Chris | Brown | +-----------+------------------+-----------------+ 4 rows in set (0.00 sec)
Advertisements
