MySQL创建数据库创建表demo

#创建数据库并设置数据库编码格式
create database student character set utf8;
use student;
#创建表
create table studentinfo(
	id int,
  stuname varchar(50),
  stuno int,
  sex varchar(2)
);
#删除表
drop table studentinfo;
create table teacherinfo(
	id int,
	teacherName VARCHAR(50),
	teacherNo int,
	sex VARCHAR(20)
);
#删除表
#drop table 表名;
#创建表的同时添加约束
/**
primary key:主键,不能为空,唯一,不可重复
主键一般和auto_increment一起使用,只适用于MySQL
设置自增类型必须是主键
not null:不能为空
unique:唯一,可以有一个空值
*/
create table studentinfo(
	id int primary key auto_increment,
	stuno int not null unique,
	stuname varchar(50) not null,
	phone varchar(100),
	idcard varchar(255),
	addr varchar(255)
);

猜你喜欢

转载自blog.csdn.net/jasmyn518/article/details/110112867
今日推荐