Mysql数据库

Mysql数据库


1.数据库基本操作

1)、创建数据库

create database dbname;

2) 、创建数据表

create table table_name (column_name1
coulumn_type1,column_name2 coulumn_type2,....)
例如:
    create table stuinfo(
    stu_no  varchar(11) not null primary key,
    stu_name varchar(50) not null,
    age int(2) ,
    gender int(1)  default 1

);
3)、插入数据

insert into table_name (column_name1,column_name2……)
values(column_value1,column_value2……)
例如:insert into stuinfo (stu_no, stu_name, age, gender) 
values ('2015123456', '小明', 23, 1);

4)、查找数据

a)、查找全部数据:select * from table_name
b)、按条件查询数据:select * from table_name where 加条件
例:select * from stuinfo where id between 3 and 8
    select * from stuinfo where id = 3 or id = 5 or id =8;
c):模糊条件查询(like not like):
        用通配符"%"和"_"占位,"_"只能占一个,"%"可以占多个.
    例如:select * from stu_info where stu_name like '%白%';
          select * from stu_info where stu_name not like '小_';
d):部分栏位查询:
    例如:select stu_name, stu_no from stuinfo;

5)、删除数据

a)、delete from table_name where 加条件
例如:delete from stuinfo where stu_no='12345678943';
b)、清空表数据TRUNCAT
例如:TRUNCATE table test.stuinfo; 

两者不同在于:
1> delete 删除所有的数据之后当事务没提交,可以将数据回滚。Truncate不可以。
2> delete 删除所有的数据之后,数据占用的空间还在,truncate 将占用的表空间也清除掉。
6)修改数据

update tb_name set col1 = value1,col2 = value2 where....;
例如:update stu_info set stu_name = '张三',gender = '男' where stu_no = '123456';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值