mysql 常用操作一

安装后登陆 -->mysql -uroot -p123456
显示所有数据库 -->show databases;
创建新的数据库 -->create database 数据库名;
删除数据库 -->drop database 数据库名;
使用数据库 -->use datsbase 数据库名;

创建表 -->create table 表名(  []内容可写可不写
-->字段1 类型[约束],
-->字段2 类型[约束]
-->foreign (主表外键字段) references 从表名(从表主键字段)
-->);
查看表结构 -->desc 表名;
显示所有表 -->show tables;
删除表 -->drop table 表名;

操作数据 增加 -->insert into 表名[指定字段名] value(字段);
删除 -->delete from 表名[条件语句]
修改 -->update 表名 set 字段1=值,字段2=值;

修改表结构 增加一列-->alter table 表名 add 字段 类型;
删除一列-->alter table 表名 drop 字段名;
修改列名-->alter table 表名 change 旧字段 新字段 新字段类型;
修改表名-->alter table 表名 rename 新表名;
更改约束-->alter table 表名 modify 字段 约束 类型;

约束条件 主键 -->alter table 表名 modify 字段 primary key; 【方法一】
-->create table score( 【方法二】
-->id int primary key,
-->score int not null
-->);

-->create table score(
-->id int primary key,
-->score int not null,

-->primary key(id) 【方法三】
-->);
外键 -->alter table 表名 modify 字段 foreign key 从表名(主键); 【方法一】
-->create table stu(
-->id int primary key auto_increment,
-->xuehao_id int not null,
-->name varchar(10) unique,
-->sex enum('男','女') default'男',
-->foreign key(xuehao_id) references score(id) 【方法二】
-->);

非空 -->not null;
默认 -->default'';
枚举 -->enum('','');
唯一 -->unique(数据唯一,null除外);
自增 -->auto_increment;

转载于:https://www.cnblogs.com/zc-beyond/p/5547526.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值