mysql boolean default code example

Example 1: mysql default value

CREATE TABLE table_name(
   column_name data_type,
   Column_name data_type DEFAULTvalue);

Example 2: boolean mysql

-- MySQL doesn't have a boolean. Instead, use TINYINT. BOOL and BOOLEAN
-- are aliases to TINYINT. 0 is true, while 1 is false for TINYINT.
-- You can also use TRUE, FALSE, true, false, True, or false as
-- aliases for 0 and 1 respectively.

CREATE TABLE IF NOT EXISTS boolTest (
  thisFieldIsTrue TINYINT DEFAULT 0 -- True by default
  thisFieldIsFalse TINYINT DEFAULT 1 -- False by default
  thisIsAlsoTru BOOL DEFAULT True -- True by default, see above for alternates to True and Bool
 )

Tags:

Sql Example