DDL 操作表和数据库(创建,删除,修改,添加,复制表)


/*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表结构*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值