mysql基本操作

1.创建数据库

create database test ;
2. 创建表
create table student (id int , name char(8) , sex char(4));
—创建了一个student表,有id name sex 三个字段
3. 查看数据表字段
select columns from student ; 
show create table student ;
describe student ;
use information_schema
select * from columns where table_name='表名';
以上方法都可以。
4. 插入数据
insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, …);
[] 内的数据可以省略
insert student values(1,’luyg’,’girl’);
插入指定数据
insert student (id,name) values(10,’kobe’);
5. 更新数据
update 表名称 set 列名称=新值 where 更新条件;
6. 删除数据
delete from 表名称 where 删除条件;
delete from test where id = 1 ;
 
7.修改表结构
基本形式: alter table 表名 add 列名 列数据类型 [after 插入位置];
示例:
在表的最后追加列 address: alter table students add address char(60);
在名为 age 的列后插入列 birthday: alter table students add birthday date after age;
8. 修改列
基本形式: alter table 表名 change 列名称 列新名称 新数据类型;
示例:
将表 tel 列改名为 telphone: alter table students change tel telphone char(13) default "-";
将 name 列的数据类型改为 char(16): alter table students change name name char(16) not null;
9. 删除列
基本形式: alter table 表名 drop 列名称;
alter table test drop name
10.重命名表
基本形式: alter table 表名 rename 新表名;
11.删除表
基本形式: drop database 数据库名;

 

posted @ 2015-03-02 22:17  luyg24  阅读(157)  评论(0编辑  收藏  举报