Home  >  Article  >  Database  >  SQL commands commonly used in database operations

SQL commands commonly used in database operations

一个新手
一个新手Original
2017-09-07 15:51:031682browse

Common sql commands for operating database structure and data

Create database

create database if not exists  数据库名  charset=指定编码

Using database

use 数据库名

Create table

create table if not exists 表名(
字段名 类型名,       
id  int,        
birth  date  
);

Show

显示表(创建表代码)
 show create table 表名字;
显示表结构
 desc 表名;
显示数据库和表
 show 数据库名/表名
rrree

##Delete

<br/>

# Add, delete, and modify the data structure check (Basically based on the modified keyword "alter")

删除数据库与表
drop 数据库名/表名
添加列
alter table 表名 add(列名 列类型,列名 列类型);
alter table tab_day1 add(age int,zwjs text);
删除列
alter table 表名 drop 列名;
alter table tab_day1 drop age;

Data addition, deletion and modification query

(这里区别change与modify,change为改变的意思,程度自然比modify大)
修改列名
alter table tab_day1 change 旧列名 新列名 新列类型;
alter table tab_day1 change money salary decimal(10,2);
修改列类型
alter table tab_day1 modify 列名 列新类型;
alter table tab_day1 modify height int;

The above is the detailed content of SQL commands commonly used in database operations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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