常用sql命令:http://www.2cto.com/database/201305/210465.html
①创建表:create table customers (cid char(4) not null, cname varchar(13),city varchar(20), discnt real, primary key(cid));
create table person(
id int not null auto_increment,
name varchar(40) not null,
city varchar(20),
salary int,
primary key(id)
)engine=innodb charset=gb2312;
②删除表:drop table 表名称; 或delete from 表名称;
③清除表中数据:truncate table users;
④插入数据:insert into 表名称 values('……','……');
⑤更新数据:UPDATE pet SET birth = '1989-08-31'WHERE name = 'Bowser' ORDER BY birth DESC;
ASC(升序,默认方式);DESC(降序)
WHERE 和 ORDER 语句也可用于查询select 与 删除delete
B树索引:http://wenku.baidu.com/view/87fbc81e10a6f524ccbf851d.html
①http://www.51cto.com/art/200512/12892_2.htm
如果在使用CREATE INDEX时,不指定任何的索引类型参数,默认创建的就是标准的B树索引,例如下面的语句在emp_index表中创建了两个不同的B树索引:
CREATE TABLE emp_index AS SELECT * FROM emp; --创建一个没有索引的表
CREATE INDEX idx_emp_empnoname ON emp_index(ename,empno);--B树索引,属于复合索引
CREATE INDEX idx_emp_job ON emp_index(job); --B树索引,属于单列索引
②http://www.51cto.com/art/200512/12892_2.htm
创建表示就添加索引:
CREATE TABLE lookup(id INT NOT NULL,name CHAR(20),
PRIMARY KEYUSING BTREE (id)
) ENGINE = MEMORY;
文件导入导出:http://www.jb51.net/article/21117.htm
①txt文件导入:
文件格式:每一项之间用Tab键进行分隔,如果该字段为NULL,则用\N表示。 记录之间换行符。
导入的命令:load data local
infile “c:/data.txt” into table person(name,age,city,salary); //括号里按文件里条目顺序写属性;
查看表格内容:select * from 表格名称
②导出txt文件:
select name,age,city,salary into outfile “c:/data_out.txt” lines
terminated by “\r\n” from person;
//其中lines terminated by “\r\n”表示每一行(即每一条记录)用\r\n分隔,\r\n是window系统的换行符。导出的data_out.txt与data.txt的内容完全一样。