
- 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
How can I store the fixed length string as well as variable length string in the same MySQL table?
As we know that CHAR is used to store fixed length string and VARCHAR is used to store variable length strings. Hence we can store a fixed length as well as variable length string in the same table by declaring a column as CHAR and other as VARCHAR.
Example
mysql> Create Table Employees(FirstName CHAR(10), LastName VARCHAR(10)); Query OK, 0 rows affected (0.64 sec) mysql> Desc Employees; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | FirstName | char(10) | YES | | NULL | | | LastName | varchar(10) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 2 rows in set (0.03 sec)
- Related Articles
- How MySQL LENGTH() function measures the string length?
- How do I get the average string length in MySQL?
- How can we retrieve the length of a specified string in MySQL?
- Set options while creating a MySQL table. Display the same options as well
- How can I store ‘0000-00-00’ as a date in MySQL?
- What MySQL returns, if the length of the original string is greater than the length specified as an argument in LPAD() or RPAD() functions?
- How can we automatically define the structure of MySQL table same as the structure of another table?
- When MySQL SUBSTRING_INDEX() function returns the same string, provided in the argument, as output?
- How can I format numbers as dollars currency string in JavaScript?
- How to fetch an Integer variable as String in GoLang?
- How can I use MySQL subquery as a table in FROM clause?
- Extract gender values as a string when it is stored in the table as a Boolean in MySQL
- Minimize length of a string by removing occurrences of another string from it as a substring
- Which MySQL function can be used to find out the length of the string in bits?
- How can I use SUBSTRING_INDEX() function to get the substring as output which is between two same delimiters in a string?

Advertisements