/*date:日期,只包含年月日,yyyy-MM-dd
datatime:日期,只包含年月日时分秒,yyyy-MM-dd HH:mm:ss(HH是24小时制,hh是12小时制)
timestamp:时间戳类型 包含年月日时分秒,yyyy-MM-dd HH:mm:ss(HH是24小时制,hh是12小时制) 如果将来不给这个字段赋值,或赋值null,则默认使用当前的系统时间,来自动赋值*/
/*创建表*/
CREATE TABLE studenttable(
id int,
name VARCHAR(32),/*32个字符*/
age int,
score DOUBLE(4,1),/*表示这个数最多4位,小数点后面取一位*/
insert_time timestamp /*使用时间戳,来获取本电脑的系统时间*/
)
show TABLES;/*查看正在使用数据的全部表*/
desc studenttable;/*查看studenttable表的结构*/
/*删除表*/
drop table hero;
drop table if exists hero;
/*复制表*/
create table table1 like studenttable;
/*修改表*/
/*修改表名*/
alter table studenttable rename to table1;
/*修改表的字符集*/
alter table studenttable character set gbk;
/*添加一列*/
alter table studenttable add gender varchar(10);
desc studenttable;
/*修改列名称 类型*/
alter table studenttable change gender sex varchar(20);
alter table studenttable modify sex varchar(10);/*只改类型*/
/*删除列*/
alter table studenttable drop sex;
查询,使用,删除数据库:
show DATABASES /*查看所有的数据库名称*/
show create database student /*查看student数据库的创建方式CREATE DATABASE `student` /*!40100 DEFAULT CHARACTER SET utf8 */
CREATE DATABASE if NOT EXISTS Student2;/*如果Student2数据库不存在,则创建数据库Student2*/
CREATE DATABASE Student2 CHARACTER SET gbk;/*设置Student2数据库的编码为gbk*/
ALTER DATABASE Student CHARACTER SET gbk;/*修改Student数据库的编码为gbk*/
DROP DATABASE Student;/*删除Student数据库*/
DROP DATABASE Student IF EXISTS Student/*如果Student数据库存在,删除数据库*/
SELECT DATABASE();/*查询正在使用的数据库名称*/
use Student;/*使用Student数据库*/
SHOW TABLES;/*查看正在使用的数据库中的表*/
desc hero;/*查询hero表结构*/