[MySQL learning articles] --- data type attributes, sorting

[MySQL learning articles]-the attributes and sorting of data types

Default value: default'default value'

Non-empty: not null modified fields must be filled in when adding information

Automatic growth: auto_increment try to be in the int field, and increment by 1 each time

Primary key: primary key A table has only one field as the primary key, as the primary key field, any two pieces of information cannot be repeated

Unique key: unique is the modified field, the data in it cannot be repeated

CREATE TABLE users(
 #id 自增 非空 作为主键
	id BIGINT(20) AUTO_INCREMENT  NOT NULL PRIMARY KEY COMMENT '用户编号',
 #username 非空
	username VARCHAR(40)NOT NULL COMMENT '用户名',
 # gender 默认为性别 女
	gender VARCHAR(2) DEFAULT '女' COMMENT '性别',
 #idcard 唯一键不能重复 非空
	idcard VARCHAR(20) UNIQUE NOT NULL COMMENT '身份证号'
);

Sort the table according to a field

#字段类型可以是数值类型 也可是字符类型,但对应字段要英文 不能是中文
#select * from 表名 order by 字段名 DESC/ASC
#降序(DESC)
SELECT * FROM users ORDER BY score DESC;
#升序(ASC)
SELECT * FROM users ORDER BY idcard ASC;

Guess you like

Origin blog.csdn.net/DREAM_yao/article/details/108076708