mysql 手写建 表_SQL创建表格——手写代码

打开phpstudy,打开Navicat for MySQL,进入要创建表格的数据库,点击上方“查询”按钮,“创建查询”,即可输入代码进行创建。

例:

create table class

(

class_id int not null  primary key,

class varchar(255) not null,

major varchar(255) not null ,

depart varchar(255) not null

);

create table stu_info

(

id int not null primary key,

name varchar(90) not null ,

sex varchar(100) not null,

age int,

class varchar(20) not null,

foreign key (class) references class(class_id)

);

create table score

(

ids int auto_increment  primary key,

stu_id int not null,

subject varchar(255) not null,

score int not null

);

注意:

1.类型包含长度的在类型后面加括号,括号里面写长度

2.上一列写完加逗号

3.最后一列不要写逗号

4.在每一条SQL语句写完之后要加分号

5.如果有外键关系,先创建主表

**自增长 auto_increment

**主键 primary key

**外键 foreign key (列名)  references 主表名(列名)

**非空 not null

创建数据库

create database test2;

删除数据库

drop database test2;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值