1、服务器连接数据库后,创建新的数据库
create database dbname default character set utf8 collate utf8_general_ci;
2、创建数据库
create database dbname;
删除数据库
drop databases dbname;
3、根据已有的表创建新表
create table new_tab as select col1,col2 from old_tab
create table new_tab as select col1,col2 from old_tab definition only
create table new_tab like old_tab(使用旧表创建新表)
删除新表
drop table new_tab;
4、导出表结构
create table new_tab select * from old_tab where 1=2 or where new_tab like old_tab
5、创建索引
create [unique] index idxname on tabname (col1.......)
删除索引
drop index idxname;
索引:使用索引可快速访问数据库表中的特定信息。索引是对数据库表中一列或多列的值进行排序的一种结构。类似于书籍的目录。
6、创建视图
create view viewname as select statement
删除视图
drop view viewname
7、创建表
create table my_table(
my_id int not null auto_increment,
my_name char(50) not null default "a tang ge",
my_city char(50) null,
my_state char(5) null,
primary key(my_id)
)engine = InnoDB;
engine = InnoDB 引擎类型
InnoDB:可靠的事务处理引擎