mysql--数据定义语言DDL
2017-07-19 12:35
309 查看
DDL对数据库的操作命令:
(1)数据库的创建:
DDL数据库表格的操作命令:
1.create创建表:
列属性的约束:
1. 自增 auto_increment
2. 主键(复合主键)primary key 默认为非空唯一primary key(stuid,carid)
3. 外键 foreign key
constraint 约束名 foreign key (外键列名)references 被参考表名(被参考列)
constraint fk_t1 foreign key(fid)references t1(uid)
alter table tte add constraint ft foreign key(uid) references t3(id)
4. 索引 index
5. 注释 comment
6. Default
7. 是否为空 null not null
8. 唯一 unique
9. 检查check
age int check(age between 18 and 25),
注意:先有主键,后有外键。主外键属性保持一致,主外键名不能重复。
自增和默认不能同时使用
列级约束 null notnull
表级约束 primarykey froreign key unique check
2.drop删除表
3.alter
(1)增加一列
(3)删除一列
(4)为表重命名
(5)为列重命名
(6)修改整个表的字符集
(1)数据库的创建:
create database + 数据库名;(2)删除数据库:
drop database + 数据库名;(3)使用该数据库:
use + 数据库名;(4)显示所有数据库
show databases;
DDL数据库表格的操作命令:
1.create创建表:
create table 名字( 列名 类型, 列名 类型, 列名 类型 ); CREATE TABLE user ( User char(16) COLLATE utf8_bin NOT NULL DEFAULT '', Select_priv enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', ssl_cipher blob NOT NULL, max_user_connections int(11) unsigned NOT NULL DEFAULT '0', authentication_string text COLLATE utf8_bin, PRIMARY KEY ('Host','User')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Users and global privileges';
列属性的约束:
1. 自增 auto_increment
2. 主键(复合主键)primary key 默认为非空唯一primary key(stuid,carid)
3. 外键 foreign key
constraint 约束名 foreign key (外键列名)references 被参考表名(被参考列)
constraint fk_t1 foreign key(fid)references t1(uid)
alter table tte add constraint ft foreign key(uid) references t3(id)
4. 索引 index
5. 注释 comment
6. Default
7. 是否为空 null not null
8. 唯一 unique
9. 检查check
age int check(age between 18 and 25),
注意:先有主键,后有外键。主外键属性保持一致,主外键名不能重复。
自增和默认不能同时使用
列级约束 null notnull
表级约束 primarykey froreign key unique check
2.drop删除表
drop table + 表名;
3.alter
(1)增加一列
alter table +表名 add 列名 类型;(2)修改一列
alter table 表名 modify 列名 修改后的类型;
(3)删除一列
alter table 表名 drop 列名;
(4)为表重命名
alter table 表名 rename to 新表名
(5)为列重命名
alter table 表名 change 原列名 新列名
(6)修改整个表的字符集
alter table 表名 charset=gbk;
相关文章推荐
- MySQL(五)之DDL(数据定义语言)与六大约束
- 【MySQL笔记】数据定义语言DDL
- mysql学习一 DDL(数据定义语言)
- 源码编译安装mysql,DDL数据定义语言的使用。
- mysql 数据定义语言(DDL)
- mysql学习一 DDL(数据定义语言)
- mysql学习笔记之六(数据定义语言DDL)
- MySQL5.6、5.7、8.0在线DDL对比情况
- MySQL分类与DDL语句实例详解
- 基于Oracle的数据定义语言DDL
- mysql DDL语言执行过程
- MySQL--- DDL、DML、DCL都包括那些语句?
- Mysql执行DDL语句错误-Incorrect key file for table
- Enterprise Architect 修改模板,适应mysql生成ddl
- Enterprise Architect 12 修改模板,适应mysql生成ddl
- MySQL5.6在线DDL不锁表(在线添加字段)
- MySQL的DDL语句
- PL/SQL DDL(数据定义语言)Data Defination Language
- MySQL 之DDL
- MySQL Online DDL