博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL创建表格——手写代码
阅读量:4308 次
发布时间:2019-06-06

本文共 841 字,大约阅读时间需要 2 分钟。

打开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;

转载于:https://www.cnblogs.com/cmzhphp2017/p/7547340.html

你可能感兴趣的文章
【循序渐进学Python】6.Python中的函数
查看>>
django ORM中的RelatedManager(关联管理器)
查看>>
VA Code编写html(1)
查看>>
C# winForm 定时访问PHP页面小工具
查看>>
编写TreeSet类的实现程序,其中相关的迭代器使用二叉查找树
查看>>
Java作业08 计科1501 闫国雨
查看>>
IntelliJ IDEA+Mysql connecter/j JDBC驱动连接
查看>>
(转)SQL Case when 的使用方法
查看>>
oc基础-self关键字的使用
查看>>
Ext JS 5 beta版发布
查看>>
牛客网第4场A
查看>>
Laravel笔记记录
查看>>
【php】【特殊案例】数组调用方法
查看>>
【php】 自带的过滤机制
查看>>
shell 1
查看>>
ubuntu14.04 boost动态库找不到 libboost_system.so.1.58.0
查看>>
linux常用命令
查看>>
castle windsor学习----- Services and Components 两者的定义
查看>>
“ddl”有一个无效 SelectedValue,因为它不在项目列表中。
查看>>
HUST-2015 Multi-University Training Contest 9
查看>>