
- 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
What type of datatype should I use (MySQL) with a mix of string and number?
To mix string and number, you need to use VARCHAR() data type. Following is the syntax −
CREATE TABLE yourTableName ( yourColumnName1 VARCHAR(40) );
Let us create a table −
mysql> create table demo28 −> ( −> id int not null auto_increment primary key, −> user_id varchar(40) −> ); Query OK, 0 rows affected (0.64 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo28(user_id) values('John_123'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo28(user_id) values('David_44'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo28(user_id) values('Mike99'); Query OK, 1 row affected (0.16 sec) mysql> insert into demo28(user_id) values('Sam101'); Query OK, 1 row affected (0.17 sec)
Display records from the table using select statement −
mysql> select *from demo28;
This will produce the following output −
+----+----------+ | id | user_id | +----+----------+ | 1 | John_123 | | 2 | David_44 | | 3 | Mike99 | | 4 | Sam101 | +----+----------+ 4 rows in set (0.00 sec)
- Related Articles
- Which datatype should I use for flag in MySQL?
- Which datatype is should I use to set a column for 5-star rating?
- What should one use CHAR data type or VARCHAR data type in MySQL?
- Which one should I use? The datetime or timestamp data type in MySQL?
- When should I use a composite index in MySQL?
- When should I use MySQL compressed protocol?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- Which MySQL Datatype should be used for storing BloodType?
- To return value of a number raised to the power of another number, we should use ^ operator in MySQL?
- Why should eval be avoided in Bash, and what should I use instead?
- MySQL isn’t inserting binary data properly? Which datatype should be used?
- How can I use MySQL INTERVAL() function with a column of a table?
- How to sum rows of VARCHAR datatype or TIME datatype in MySQL?
- PHP string cast vs strval function, which one should I use?
- What MySQL returns if I use enclosed set of unit values with INTERVAL keyword?

Advertisements