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;