Home > Database > Mysql Tutorial > mysql常用的一些语句_MySQL

mysql常用的一些语句_MySQL

WBOY
Release: 2016-06-01 13:45:00
Original
861 people have browsed it

bitsCN.com

创建表

create TABLE emp(
id INT(10) unsigned NOT NULL AUTO_INCREMENT,
emp_no VARCHAR(10) NOT NULL,
emp_name VARCHAR(50) NOT NULL,
emp_sex CHAR(1) default null,
emp_salary DOUBLE(10,2) default NULL,
birthday Date default null,
entry_date TIMESTAMP(8),
PRIMARY KEY (`id`)
)ENGINE=InnoDB  DEFAULT CHARSET=utf8

插入数据
insert into emp(emp_no,emp_name,emp_sex,emp_salary,birthday)values('1001','zhansan','M',5000.345555,'2004-09-23');

添加表字段number在cityId后
alter table emp ADD number INT(10) after emp_name;

修改表的字段名字定义
alter table emp change emp_name  emp_namedd VARCHAR(55);

修改表的字段的定义位置
alter table emp modify emp_name VARCHAR(20)  default 'zhangsan';

删除表的字段
alter table emp drop emp_name;

删除表
drop table emp;

清空表数据
truncate table emp;

得到表结构
desc emp;

这个是用来对表进行优化。这个命令可以将表中的碎片进行合并,并且可以消除由于删除或者更新造成的空间的浪费。这个命令只对MyISAM BDB,InnoDB起作用。
OPTIMIZE TABLE emp;

创建过程:向表emp中插入10000条数据
create PROCEDURE createEmpData()
BEGIN
set @x=1;
loop1:LOOP
set @x = @x + 1;
  if @x = 10000 THEN
LEAVE loop1;
end IF;
insert into emp(emp_no,emp_name,emp_sex,emp_salary,birthday)values('1001','zhansan','M',5000.34,'2004-09-23');
end loop loop1;
END

调用过程
call createEmpData;

删除过程
drop PROCEDURE createEmpData;

作者“ylq365”
 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template