创建表
CREATE TABLE IF NOT EXISTS Website (
`id` INT UNSIGNED AUTO_INCREMENT comment 'ID',
`name` VARCHAR(80) comment '姓名',
`url` VARCHAR(120) comment '链接地址',
`alexa` INT UNSIGNED comment '流量',
`country` VARCHAR(10) comment '国家',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
CREATE TABLE IF NOT EXISTS apps (
`id` INT UNSIGNED AUTO_INCREMENT comment 'ID',
`app_name` VARCHAR(80) comment 'App名称',
`url` VARCHAR(120) comment '链接地址',
`country` VARCHAR(10) comment '国家',
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=UTF8;
CREATE TABLE `runoob_tbl` IF NOT EXISTS (
`runoob_id` int unsigned NOT NULL AUTO_INCREMENT,
`runoob_title` varchar(40) DEFAULT NULL,
`runoob_author` varchar(40) DEFAULT NULL,
`runoob_submission_date` datetime DEFAULT NULL,
PRIMARY KEY (`runoob_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
查看所有表
当前数据库
SHOW TABLES;
其他数据库
SHOW TABLES FROM `student`;
查看表结构
常规表结构
DESC `website`;
带注释的表结构
SHOW FULL COLUMNS FROM `website`;
查看创建表的语句
SHOW CREATE TABLE `website`;
修改表
修改表名
ALTER TABLE `website` RENAME TO `new_website`;
修改表注释
ALTER TABLE `website` COMMENT '测试表';
修改字符集
ALTER TABLE `runoob_tbl` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
删除表
DROP TABLE `website`;
DROP TABLE `apps`;
网友评论