Database operations
Create a database
grammar
A grammar: the Create Database database name syntax two: the Create Database database name Character the SET character set;
View database
grammar
All database View database server: show databases; information defined in a database of view: Show the Create Database database name;
Delete Database
Syntax ( caution )
drop Database database name;
Other database operations command
grammar
Switching database: use the database name; you currently are using a database: the SELECT Database ();
Operating Table
Field Type
Common type
Numeric: int
Float: double
Character: varchar (variable length character string)
Date Type: date (only date, not minutes and seconds)
datetime (date, minutes and seconds)
boolean type: Does not support
Create a table
grammar
create table 表名( 字段名 类型(长度) 约束, 字段名 类型(长度) 约束 ); 单表约束: * 主键约束:primary key * 唯一约束:unique * 非空约束:not null * 注意:主键约束 = 唯一约束 + 非空约束
Example
CREATE TABLE sort ( sid INT PRIMARY KEY, #分类ID sname VARCHAR(100) #分类名称 );
查看表
语法
查看数据库中的所有表:show tables; 查看表结构:desc 表名;
删除表
语法
drop table 表名;
修改表
语法
alter table 表名 add 列名 类型(长度) 约束; --修改表添加列. alter table 表名 modify 列名 类型(长度) 约束; --修改表修改列的类型长度及约束. alter table 表名 change 旧列名 新列名 类型(长度) 约束; --修改表修改列名. alter table 表名 drop 列名; --修改表删除列. rename table 表名 to 新表名; --修改表名 alter table 表名 character set 字符集; --修改表的字符集