- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use special characters in column names with MySQL?
Using backticks around the column name will allow you to use special characters. Let us first create a table −
mysql> create table DemoTable -> ( -> `Student-Id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> `Student-Name` varchar(100), -> `Student-Age` int -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(`Student-Name`,`Student-Age`) values('Chris',21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(`Student-Name`,`Student-Age`) values('Mike',19); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(`Student-Name`,`Student-Age`) values('Bob',18); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+--------------+-------------+ | Student-Id | Student-Name | Student-Age | +------------+--------------+-------------+ | 1 | Chris | 21 | | 2 | Mike | 19 | | 3 | Bob | 18 | +------------+--------------+-------------+ 3 rows in set (0.00 sec)
Advertisements