Home > Database > Mysql Tutorial > SQL commands commonly used in database operations

SQL commands commonly used in database operations

一个新手
Release: 2017-09-07 15:51:03
Original
1741 people have browsed it

Common sql commands for operating database structure and data

Create database

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

Using database

use 数据库名
Copy after login

Create table

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

Show

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

##Delete

<br/>
Copy after login

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

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

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;
Copy after login

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!

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