MariaDB数据类型能够分为数字,日期和时间以及字符串值。sql
使用数据类型的原则:够用就行, 尽可能使用范围小的,而不用大的code
--显示当前时间 select now(); --建立classes表(id, name) create table zzzz( id int primary key not null auto_increment, name varchar(20), age int ); --查看表结构 desc haha(表名) --建立students表(id, name, age, high, gender, cls_id) create table students ( id int unsigned not null auto_increment primary key, name varchar(20), age tinyint unsigned default 0, high decimal(5,2), gender enum('男', '女', '中性', '保密') default '保密', cls_id int unsigned ); --建立classes表(id, name) create table classes( id int unsigned not null auto_increment primary key, name varchar(20) ); --查看表的建立 desc classes --MyISAM与InnoDB区别 --两种类型最主要的区别就是InnDB支持事物处理与外键和行级锁 --修改表-添加字段 --alter table 表名 add 列名 类型; alter table students add birthday datetime; -- 修改表-修改字段:不重命名版 -- alter table 表名 modify 列名 类型及约束; alter table students modify birthday date; -- 修改表-修改字段:重命名版 -- alter table 表名 change 原名 新名 类型及约束; alter table students change birthday birth date; -- 修改表-删除字段 -- alter table 表名 drop 列名; alter table students drop birthday; -- 删除表 -- drop table 表名; drop table students; --增删改查 --增长 --全列插入 --insert into 表名 values(..) --主键字段 能够用0 null default 来站位 -- 向students表里插入 一个学生信息 insert into students values (0,'小明',19,188.999,'男', 1); --部分插入 insert into students(id, name, age) values (0,'绿帽子',19); --部分插入(多条记录) insert into students(id, name, age) values (0,'绿帽子',19),(0,'小跳蚤',21); --修改 --update 表名 set 列1=值1, 列2=值2... where 条件; update students set age=100 where id=1; update students set age=100,cls_id=77 where id=1; --删除 -- 物理删除 -- delete from 表名 where 条件 delete from students where cls_id=88; -- 逻辑删除 -- 用一条字段来表示 这条信息是否已经不能在使用了 -- 给students表添加一个is_delete字段 bit 类型 alter table students add is_delete bit default 0; update students set is_delete=1 where id=6;