mysql-操作库和表

管理库

创建库

create database [if not exists] 库名;

删除库

drop databases [if exists] 库名;

建库通用的写法


drop database if exists 旧库名;
create database 新库名;

创建表

create table 表名(
字段名1 类型[(宽度)] [约束条件] [comment ‘字段说明’],
字段名2 类型[(宽度)] [约束条件] [comment ‘字段说明’],
字段名3 类型[(宽度)] [约束条件] [comment ‘字段说明’]
)[表的一些设置];

create table test2(
-> a int not null comment '字段a',
-> b int not null default 0 comment '字段b'
-> );

default value:为该字段设置默认值,默认值为value
primary key:标识该字段为该表的主键,可以唯一的标识记录,插入重复的会报错
foreign key:为表中的字段设置外键

猜你喜欢

转载自blog.csdn.net/qq_41358574/article/details/113362488