mysql data field attributes

UnSigned

  • unsigned
  • Declare that the data column does not allow negative numbers 

 ZEROFILL

  • 0 filled
  • If the number of digits is insufficient, use 0 to fill, such as int(3), 5 is 005

 Auto_InCrement

  • Auto-growth, each time a piece of data is added, automatically add 1 to the previous record number (default)
  • Usually used to set the primary key, and is an integer type
  • Definable starting value and step size   
  1. Current table setting step size (AUTO_INCREMENT=100): only affects the current table
  2. SET @@auto_increment_increment=5 ; Affects all tables using auto-increment (global)

 NULL 和 NOT NULL

  • The default is NULL, that is, no value is inserted into the column
  • If set to NOT NULL , the column must have a value

 DEFAULT

  • default
  • Used to set the default
  • For example, the gender field defaults to "male", otherwise it is "female"; if no value is specified for this column, the default value is "male"
-- 目标 : 创建一个school数据库
-- 创建学生表(列,字段)
-- 学号int 登录密码varchar(20) 姓名,性别varchar(2),出生日期(datatime),家庭住
址,email
-- 创建表之前 , 一定要先选择数据库
CREATE TABLE IF NOT EXISTS `student` (
`id` int(4) NOT NULL AUTO_INCREMENT COMMENT '学号',
`name` varchar(30) NOT NULL DEFAULT '匿名' COMMENT '姓名',
`pwd` varchar(20) NOT NULL DEFAULT '123456' COMMENT '密码',
`sex` varchar(2) NOT NULL DEFAULT '男' COMMENT '性别',
`birthday` datetime DEFAULT NULL COMMENT '生日',
`address` varchar(100) DEFAULT NULL COMMENT '地址',
`email` varchar(50) DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
-- 查看数据库的定义
SHOW CREATE DATABASE school;
-- 查看数据表的定义
SHOW CREATE TABLE student;
-- 显示表结构
DESC student; -- 设置严格检查模式(不能容错了)SET
sql_mode='STRICT_TRANS_TABLES';

Guess you like

Origin blog.csdn.net/qq_41081716/article/details/130176787