数据库与表的操作语句

例:create database if not exists `intheima`;
    use `itheima`;
    create table if not exists `student`(
    `id` int unsigned primary key auto_increment comment `学号`,
    `name` varchar(32) not null comment `姓名`,
    `gender` enum(`男`,`女`) default `男` not null comment `性别`
)default charset=utf8;

一、数据库
create database `intheima`;(创建MySQL数据库)
create database if not exists `intheima`;(创建MySQL数据库)自动判断数据库的名字是否存在
show create database; (查询数据库)
show databases;(查询MySQL所有数据库)
use `intheima`;(选择数据库)
drop database `intheima`;(删除数据库)
二、表
show tables;(查看数据库中有哪些表)
desc `student`;(查看指定表字段信息)
desc `student` `name`;(查看表的某一列信息)
show create table `student`\G(查看数据表的创建语句和字符串编码)
show columns from `student`;(查看表的结构)
alter table `student` add `area` varchar(100);(添加字符)
alter table `student` change `area` `desc` char(50);(修改字符串名称)
alter table `student` modify `desc` varchar(255);(修改字符串类型)
alter table `student` drop `desc`;(删除指定字段)
alter table `student` rename `stu`;(修改数据表名称)
rename table `stu` to `student`;(将名字为stu的从命名为student)
drop table if exisis `student`;(删除存在的数据表student)
三、数据表单查询语句
1.查看数据库的所有的表
select * from `subject1`;
2.查询指定字段
select `name`,`id` from `subject1`;
指定字段(设置别名)
select `name` as `code` from `subject1`;
3.条件查询(比较运算符)(= <> != < <= > >=)
select * from `subject1` where `price`=89;
select * from `subject1` where (`id`,`price`)=(10,89);
4.带distinct关键字查询
select distinct `name`,`sex` from `subject1`;
5.带in关键字的查询  in--包含, not in---不包含
select *from `subject1` WHERE `id`in (1,6); 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值