mysql
- mysql is a relational database, used, need to create a database (database) in advance, the data table (table) do not need to create in advance by object-relational mapping framework can be resolved.
- Database (database)
- Displays the version of the database:
- select version();
- Creating a database
- create database database name of the charset = utf8;
- create database goods charser=utf8;
- Statement to check the database created
- show create database database name;
- View current database used
- select database();
- Use Database
- use the database name
- use goods;
- Delete Database
- drop database database name;
- data sheet:
- View all the tables in the current database
- show tables;
- Create a table
- auto_increment means the automatic growth, not null representation can not be null, primary key primary key represents the default default key
- create table students(id int ,name varchar(30));
- sql statement to view the table created;
- show create table students;
create table students(
id int unsigned not null auto_increment primary key,
name varchar(30),
age tinyint unsigned default 0,
high decimal(5,2),
gender enum("男", "女", "中性", "保密") default "保密",
cls_id int unsigned
);
- Adding fields and removing fields
alter table students add bith date;
alter table students drop high;
alter table 表名 add 字段 约束;
alter table 表名 drop 字段;
- Constraints modify the field of
alter table students modify birthday datatime;
- Name and constraints modify the field
alter talbe students change birthday birth date default "200-01-01";
Delete Data Sheet
drop table 表名
drop database 数据库名,删除数据库同时也把表删除了
- mysql modify the table name
rename table table1 to table2;
rename table class to classes;