MySQL 一般操作语句

//创建数据库(PHP中MySQL语句结尾不用加;,因为PHP中MySQL语气每次只能执行一句)
create database testdatabase;

//选择数据库
use testdatabase;

//创建数据表
create table test_table(first_name varchar(30),last_name varchar(30));

//显示数据表机构
descrjbe test_table
//向数据表插入数据 insert into test_table(first_name,last_name)values('Sally','Jones');
//这个不太好
insert into test_table values('Sally','Jones');
//查询数据 select * from test_table; select first_name from test_table; select first_name from test_table where first_name='Sally';
//排序 desc(降序) asc(升序)
select * from test_table order by age desc,score asc;
//清空数据表数据 delete from test_table; //删除数据表一行数据 delete from test_table where first_name='Sally' or last_name='Jones'; //删除数据表 drop table test_table; //删除数据库 drop database testdatabase; //为数据表增加一列 alter table test_table add id int; //为数据表增加一列,并设置为主键(不许为空,自增,放在表最前面) alter table test_table add id int not null auto_increment first, add primary key(id); //删除数据表中的一列 alter table test_table drop column first_name;
//修改数据表的表名
alter table tes_table rename to test_table

//修改数据表一列的列名和数据类型 alter table test_table change column first_name middle_name char; //修改数据表一列的列名,位置 alter table test_table modify column first_name middle_name; alter table test_table modify column first_name first; alter table test_table modify column last_name after middle_name;

 

转载于:https://www.cnblogs.com/nb08611033/p/8387573.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值