
- 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 use âWhenâ as column name in CREATE TABLE statement?
Before beginning, let us try to set ‘when’ as column name while using CREATE TABLE statement −
mysql> create table DemoTable693( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), When datetime );
This will produce the following output. An error would be visible:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'When datetime at line 5
You need to wrap the reserved word using backticks, for example, `when`. Let us first create a table and implement the same:
mysql> create table DemoTable693 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), `When` datetime ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command:
mysql> insert into DemoTable693(StudentName,`When`) values('Chris',NOW()); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable693(StudentName,`When`) values('Robert',CURDATE()); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement -
mysql> select *from DemoTable693;
This will produce the following output -
+-----------+-------------+---------------------+ | StudentId | StudentName | When | +-----------+-------------+---------------------+ | 1 | Chris | 2019-07-21 18:57:19 | | 2 | Robert | 2019-07-21 00:00:00 | +-----------+-------------+---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Can we use ârankâ as column name with MySQL8?
- Can we use reserved word âindexâ as MySQL column name?
- How can we use WHERE condition when creating a table with CTAS (Create Table as Selected) script?
- Can we use âyearâ as a column came in a MySQL Table?
- Will âcreate table tableâ work in MySQL since we cannot use reserved words as table name?
- Can we use MySQL keyword as alias name for a column?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- Why can't we use column name âdescâ in MySQL?
- Can we use current_date() for table with column timestamp default in MySQL?
- Can we create a table with a space in name in MySQL?
- How can we use MySQL EXPORT_SET() function with column of a table?
- How can we use MySQL SELECT statement to count number of rows in a table?
- Can we use Switch statement with Strings in java?
- How we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we create a new MySQL table by selecting specific column/s from another existing table?

Advertisements