create table <表名> (<字段名 1> <类型 1> [,..<字段名 n> <类型 n>]);
mysql> create table students (
id int(4) not null primary key auto_increment,
name char(20) not null,
address char(100)
) ;
创建text类型
CREATETABLE students (
`name`char(10) notnull,
`note` text
);
查询表中数据
mysql> select * from 表名;
mysql> select * from 表名\G; //mysql中,在sql语句后面加\G表示将查询结果按列排列,方便打印后查看。
插入数据
//插入所有列值
insert into 表名 values(值1,值2,值3....);
insert into students values(12345678901,'孙同学','stx@qq.com','女');
//插入部分列值
insert into 表名(列名1,列名2,列名3,...) values(值1,值2,值3,...);
insert into students(stuid,stuname)values(123456789014,'王同学');
在表中增加字段(列)
alter table 表名 add 字段 类型 其他;
mysql> alter table students add passtest int(4) default'0'//在表 MyClass 中添加了一个字段 passtest,类型为 int(4),默认值为 0
修改表数据
update 表名 set 列名1=值1,列名2=值2,列名3=值3..... [where 过滤条件]
update students set sex='女'where stuname='王同学';
修改表名
rename table 原表名 to 新表名;
删除数据
deletefrom 表名 [过滤条件] //注:不加过滤条件表示删除整个表所有内容deletefrom students; //删除整个表所有内容deletefrom students where sex='女'; //删除所有sex='女'的student数据信息
删除数据库中的数据表
mysql> drop table 表名;
删除数据表表中的字段(列)
altertable 表名 drop 字段
mysql> altertable tablename drop columnname;