1029レビュー

昨日のレビュー

表1.操作

増加

create table 表名(
    字段名 字段类型[字段约束]
    ....
)charset=utf8

フィールドタイプ

デジタル

整数

tinyint
smallint
int     *********************
mediumint
bigint

区别 :
    取值的范围不一样
    加上unsigned,代表只能取整数

フロート

float
double
decimal(10,5)

文字列型

char()  定长
    身份证,手机号
varchar()   变长
    哈希密码

区别:
    1.char(4)  'ab  ' 占4个字节,剩余的不足字节用空字节补充
    2.varchar(4) 'ab' 占3个字节,其中有两个是自身的大小,还有一个是记录字节的大小

タイムタイプ

日付時刻**************

年月日时分秒

数え上げます

enum
gender enum('male','female') default 'female';

列制約(オプションのパラメータ)

auto_increment  自增
not null    不能为null
primary key     主键索引
default     默认值

削除

drop table 表名;

フィールド名を削除します。

alter table 表名 drop 字段名;

変更

新しいテーブルのフィールド

alter table 表名 add 列声明;
alter table 表名 add 列声明 frist;
alter table 表名 add 列声明 after 字段名;

テーブルのフィールド名の変更

alter table 表名 modify 字段名 字段类型[字段约束]
alter table 表名 change 旧字段 新字段 字段类型[字段约束];

検索

show tables;

動作データ列

増加

insert into 表名(列1,列2) values(值1,值2),(值1,值2);

削除

delete from 表名;
    自增继续加1,一行行删除
truncate 表名;
    全选删除,自增键重新开始,速度快

条件の削除

delete from 表名 where id=10;
delete from 表名 where id=10 and name='n';

変更

update 表名 set name='zekai',age=12;

条件のように変更

update 表名 set name='zekai', age=15 where age=12 and num=10;

検索

select * from 表名;   返回表中所有数据
select 列名1,列名2 from 表名;

条件で検索

select * from where id=10;

between...and...

select * from 表名 id between 30 and 40;

個別の重複排除

select distinct name from t6;

クエリで

select 

あいまいクエリのような

算術

無効である

表1.シングルオペレーション

パケット

すべてのデータパケットは、同じフィールドに応じて分類されています

グループによる

注文

限定

2.マルチテーブル操作

外部キー

3.mysqlバックアップ

create table department(
                id int auto_increment primary key,
                name varchar(32) not null default ''
            )charset utf8;
            
            insert into department (name) values ('研发部');
            insert into department (name) values ('运维部');
            insert into department (name) values ('前台部');
            insert into department (name) values ('小卖部');
            
            create table userinfo (
                id int auto_increment primary key,
                name varchar(32) not null default '',
                depart_id int not null default 1,
                constraint fk_user_depart foreign key (depart_id) references department(id)
            )charset utf8;
            
            insert into userinfo (name, depart_id) values ('zekai', 1);
            insert into userinfo (name, depart_id) values ('xxx', 2);
            insert into userinfo (name, depart_id) values ('zekai1', 3);
            insert into userinfo (name, depart_id) values ('zekai2', 4);
            insert into userinfo (name, depart_id) values ('zekai3', 1);
            insert into userinfo (name, depart_id) values ('zekai4', 2);
            insert into userinfo (name, depart_id) values ('zekai4', 5);

おすすめ

転載: www.cnblogs.com/fwzzz/p/11779546.html