MySQL简单语法(1)
来源:互联网 发布:asp网站sql注入 编辑:程序博客网 时间:2024/06/03 08:38
创建数据库
create database DATA;
切换数据库
use DATA;
创建表
create table t1
(
id vachar(10) not null.
name text,
number char(10) not null,
a1 double not null
)
##为列添加约束
- 主键约束。保证实体完整性
create table t1
(
user_qq varchar(20) not null primary key,
user_name varchar(20) not null,
user_sex char(2) not null,
user_birthday datetime not null
) - 外键约束。保证引用完整性
create table scores
(
user_qq vachar(20) not null references ‘users’(userqq),
gno int not null references ‘games’(gno),
score int not null
)
3 检查约束作用:保证域完整性
CREATE TABLE Games
(
GNO int not null CHECK(GNO>0),
GName VARCHAR(20) not null,
GType varchar(20) not NULL
)
演示发现,GNO列可以添加负数,但是不可以输入其他字符。
4 默认约束。保证域完整性
create table ne
(
usersex char(2) default ‘男’,
usermm text not null
)
5 自增列
CREATE table t02
(
m int not null PRIMARY key auto_increment,
h int not null
)
自增列必须设置为主键
删除数据表
- 删除无关联的数据表
drop table data,t11
2 删除有关联的数据表
当两张表有主外键关系的话,应该先删除外键,我们可以通过解除关联关系,然后再删除主键数据表。
解除关联关系(alter 后面是从表)
alter table biao1 drop foreign key con_name
删除表
drop table data,t11
阅读全文
0 0
- MySQL简单语法(1)
- MySQL简单语法(2)
- MySQL简单语法(3)
- MySQL简单语法(4)
- MySQL简单语法(6)
- MySQL简单语法(7)
- MySQL简单语法(8)
- MySQL简单语法(图片)
- 我的MYSQL学习心得(1) 简单语法
- MySQL学习系列1:简单语法
- MySQL与MongoDB语法对比(简单)
- MySql简单语法复习
- MySQL<一>简单语法
- 简单的MYSQL语法
- MySql的简单语法
- MySQL简单语法(5)
- MYsql 存储过程简单语法
- MYsql 存储过程简单语法
- Token存储方式JWT
- Python神器--VirtualEnv
- linux下预处理、编译、汇编、链接及gdb调试
- 前端小案例-纯css做缩略图悬停效果
- ACM-12月3日周日周末训练心得
- MySQL简单语法(1)
- C# Linq版七层登录
- Mondriaan's Dream
- 19 迭代器iterator的设计原则(学自Boolean)
- AQSENSE 3D acquisition and processing Tools
- caioj【1101】:统计颜色(模板题) 线段树(lazytag)+离散化
- Java定时任务之Timer的使用
- tddl+diamond(一)
- LeetCode#712 Minimum ASCII Delete Sum for Two Strings题解(C++版)