
- 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
Which datatype should I use for flag in MySQL?
To set a flag, you can set the type as tinyint(1) type.
Following is the syntax −
yourColumnName tinyint(1) DEFAULT 1;
Let us first create a table −
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), isMarried tinyint(1) DEFAULT 1 ); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> INSERT INTO DemoTable(ClientName,isMarried) values('Larry',0); Query OK, 1 row affected (0.16 sec) mysql> INSERT INTO DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO DemoTable(ClientName,isMarried) values('Mike',1); Query OK, 1 row affected (0.19 sec) mysql> INSERT INTO DemoTable(ClientName) values('Carol'); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output that displays one of the column, which is set as flag −
+----------+------------+-----------+ | ClientId | ClientName | isMarried | +----------+------------+-----------+ | 1 | Larry | 0 | | 2 | David | 1 | | 3 | Mike | 1 | | 4 | Carol | 1 | +----------+------------+-----------+ 4 rows in set (0.00 sec)
- Related Articles
- Which MySQL Datatype should be used for storing BloodType?
- Which datatype is should I use to set a column for 5-star rating?
- What type of datatype should I use (MySQL) with a mix of string and number?
- For timestamp, which datatype is used in MySQL?
- MySQL isn’t inserting binary data properly? Which datatype should be used?
- Which one should I use? The datetime or timestamp data type in MySQL?
- When should I use MySQL compressed protocol?
- When should I use a composite index in MySQL?
- Should I use PyCharm for Programming in Python?
- Should I use , , or for SVG files?
- Should I use MySQL enum or tinyint for fields having values 1 and 0?
- How should I display MySQL database that is currently in use?
- Should I use COUNT(*) to get all the records in MySQL?
- What is the best datatype for currencies in MySQL?
- What is the smallest datatype for one bit in MySQL?

Advertisements