
- 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
Change tinyint default value to 1 in MySQL?
You can use DEFAULT command for this. Following is the syntax −
alter table yourTableName change yourColumnName yourColumnName TINYINT(1) DEFAULT 1 NOT NULL;
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20), UserAge int, isMarried tinyint(1) ); Query OK, 0 rows affected (0.80 sec)
Let us check the description of table −
mysql> desc DemoTable;
This will produce the following output −
+-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(20) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | isMarried | tinyint(1) | YES | | NULL | | +-----------+-------------+------+-----+---------+----------------+ 4 rows in set (0.21 sec)
Following is the query to change tinyint default value to 1 −
mysql> alter table DemoTable change isMarried isMarried TINYINT(1) DEFAULT 1 NOT NULL; Query OK, 0 rows affected (1.29 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again. The default value of tinyint has been changed to 1 −
mysql> desc DemoTable;
This will produce the following output −
+-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(20) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | isMarried | tinyint(1) | NO | | 1 | | +-----------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
- Related Articles
- What is the difference between MySQL TINYINT(2) vs TINYINT(1)?
- Does MySQL converts bool to tinyint(1) internally?\n
- Does MySQL Boolean “tinyint(1)” holds values up to 127?
- MySQL TINYINT type to return 1 or IS NULL records
- Change value from 1 to Y in MySQL Select Statement?
- What is difference between Boolean and tinyint(1) in MySQL?
- Is there a difference in using INT(1) vs TINYINT(1) in MySQL?
- Reset MySQL field to default value?
- What is the difference between TINYINT(1) and Boolean in MySQL?
- How to modify column default value in MySQL?
- How to set default Field Value in MySQL?
- Change MySQL default character set to UTF-8 in my.cnf?
- How to set default value to NULL in MySQL?
- How to set MySQL default value NONE?
- Who to Change the Default Display Value using CSS

Advertisements