Home > Database > Mysql Tutorial > body text

MySQL数据库常用命令总结_MySQL

WBOY
Release: 2016-06-01 13:10:56
Original
860 people have browsed it

MySQL数据库常用命令总结

1.先判断数据库/表是否存在,再建立数据库/表
CREATE DATABASE IF NOT EXISTS database_name;CREATE TABLE IF NOT EXISTS table_name;
Copy after login

2.MySQL修改表名,MySQL修改表的名称
AITER TABLE table_old_name RENAME [TO] table_new_name; RENAME TABLE table_old_name TO table_new_name;
Copy after login

3.MySQL添加列,MySQL增加列
ALTER TABLE table_name ADD column_name data_type NOT NULL DEFAULT xxx [AFTER/BEFORE] column_name;ALTER TABLE person ADD age tinyint NOT NULL DEFAULT 16 AFTER name;
Copy after login

4.MySQL删除列
ALTER TABLE table_name DROP [COLUMN] column_name;ALTER TABLE person DROP COLUMN age;
Copy after login

5.MySQL修改列
ALTER TABLE table_name CHANGE [COLUMN] column_old_name column_new_name 列声明
Copy after login

6.MySQL修改列的数据类型,仅仅修改列的数据类型
ALTER TABLE table_name MODIFY [COLUMN] column_name data_type;ALTER TABLE person MODIFY COLUMN age int NOT NULL DEFAULT 16;
Copy after login

7.MySQL建立索引
ALTER TABLE table_name ADD index/unique/fulltext [索引名](列名); 不加索引名,则直接以列名命名 ALTER TABLE table_name ADD primary key (列名);
Copy after login

8.MySQL删除索引
ALTER TABLE table_name DROP index 索引名; ALTER TABLE table_name DROP primary key;
Copy after login

9.MySQL查看所有的索引
show index from table_name; show index from table_name/G;
Copy after login

10.MySQL中/G的作用
MYSQL语句中使用/G参数改变输出结果集的显示方式 


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