日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

MySQL數(shù)據(jù)庫 SQL語句詳解

 孟船長 2022-12-12 發(fā)布于內(nèi)蒙古

數(shù)據(jù)庫常用操作

操作語句
創(chuàng)建數(shù)據(jù)庫create database if not exists 數(shù)據(jù)庫名;
查看所有數(shù)據(jù)庫show databases;
切換數(shù)據(jù)庫use 數(shù)據(jù)庫名;
刪除數(shù)據(jù)庫drop database if exists 數(shù)據(jù)庫名;
修改數(shù)據(jù)庫編碼alter database 數(shù)據(jù)庫名 character set utf8;

表結(jié)構(gòu)常用操作

操作語句
創(chuàng)建表create table if not exists 表名(字段名 數(shù)據(jù)類型, 字段名 數(shù)據(jù)類型, ...);
查看當(dāng)前數(shù)據(jù)庫所有表show tables;
查看表結(jié)構(gòu)desc 表名;
查看指定表的創(chuàng)建語句show create table 表名;
刪除表drop table 表名;
添加列alter table 表名 add 列名 數(shù)據(jù)類型(長度);
修改列名和類型alter table 表名 change 舊列名 新列名數(shù)據(jù)類型(長度);
刪除列alter table 表名 drop 列名;
修改表名rename table 表名 to 新表名;

增刪改

操作語句
向表中插入列insert into 表名(列1, 列2, 列3) values(值1, 值1, 值1), (值2, 值2, 值2);
向表中所有列插入數(shù)據(jù)insert into 表名 values(值1, 值1, 值1);
數(shù)據(jù)修改update 表名 set 字段名=值, ... , 字段名=值 where 條件
刪除表中數(shù)據(jù)delete from 表名 where 條件
刪除表truncate 表名

MYSQL約束

操作語句
主鍵primary key
刪除主鍵約束alter table 表名 drop primary key;
自增長auto_increment
非空not null
創(chuàng)建表前指定create table 表名(id int not null, account varchar(20) not null);
創(chuàng)建表后指定alter table 表名 modify id int not null;
刪除非空約束alter table 表名 modify 字段 類型
唯一unique
刪除唯一約束alter table 表名 drop index 唯一約束名
默認(rèn)default
刪除默認(rèn)約束alter table 表名 modify 列名 類型 default null
零填充zerofill
刪除零填充約束alter table 表名 modify 字段 類型
外鍵foreign key

如果您覺得有幫助,請幫忙點(diǎn)一下公眾號(hào)文中和最底部的廣告,點(diǎn)一下就可以,謝謝~

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多