DDL
来源:互联网 发布:网络正常微信连接不上 编辑:程序博客网 时间:2024/05/22 02:09
DDL data define language
create table / index / view drop table alter table add column /modify column /drop columndesc
# 加外键,orderbooklist(order_no)-> orderlist(order_no)alter table orderbooklist add foreign key (order_no) references orderlist(order_no);
表之间的关系
一对一 、一对多、多对一、多对多
关联关系写在多的一方
如果是多对多则新建关系表
DDL
/*用旧表创建一个新表*/create table new_stu like stu;desc new_stu;/*从旧表中选一些字段组成新表*/create table stu_2 as select id,name,height from stu;desc stu_2;/*创建索引*/create index stu_dex on stu(name);select*from stu where stu.name='x';/*删除索引*/drop index stu_dex on stu;CREATE TABLE `clazz` ( `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键', `name` VARCHAR(50) NOT NULL DEFAULT '0', `stu_count` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`));CREATE TABLE `sstu` ( `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键', `name` VARCHAR(25) NOT NULL COMMENT '姓名', `class_id` INT(11) NOT NULL, `gender` CHAR(1) NOT NULL COMMENT '性别', `birthday` DATETIME NOT NULL COMMENT '出生年月', `height` DECIMAL(5,2) NOT NULL COMMENT '身高', PRIMARY KEY (`id`));/*创建视图*/create view stu_view as select sstu.name as sstu_name,clazz.name as class_namefrom sstu,clazzwhere sstu.class_id=clazz.id;drop view stu_view;###########create database sms;use sms;create table student( stu_no varchar(20) not null primary key, sto_name varchar(50) not null);information_schemainformation_schemadesc student;/*描述表结构*/studentdrop table student;#创建表create table students( id int not null auto_increment/*自动加*/ primary key comment '主键', name varchar(50) not null comment '姓名', sex char(1) not null comment '性别', birthday datetime not null comment '生日', height decimal(5,3) not null comment '身高' );#添加列alter table students add column vision decimal(2,1) not null comment '视力';desc students;#删除列alter table students drop column vision;desc students;#修改列alter table students modify column sex char(2) not null comment '性别';desc students;alter table students change column sex gender char(2) not null comment '性别';desc students;#重命名表rename table students to stu;desc stu;/*创建表*/create table shop( id int not null auto_increment primary key comment '主键', name varchar(20) not null comment '名字', price decimal(10,2) not null comment '价格');#添加列alter table shop add column shopdate datetime not null comment '日期';desc shop;#删除列alter table shop drop column price;desc shop;#修改列alter table shop change column name shopname varchar(50) not null comment '名字';desc shop;
常用数据类型:
数值型:
日期型
字符串型
阅读全文
0 0
- DDL
- ddl
- ddl
- ddl
- DDL
- DDL
- DDL
- 什么是DDL
- DDL.DML
- ddl操作
- analyze DDL
- Oracle DDL
- DDL锁
- DDL触发器
- sql DDL
- DDL语句
- DML DDL
- DDL Parameters
- UESTC
- 20-Vue 组件
- nodejs 简易守护进程
- 学习PWM的一些总结
- 用Java统计单词出现的次数
- DDL
- @Component,@Repository、@Service 和 @Controller注解说明
- oracle中间的数据类型
- 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。
- 实验吧-围在栅栏中的爱WriteUp
- 判断一个数阶乘N!的尾数中零的个数
- HDU 2377 Bad Cowtractors(最大生成树-Kruskal)
- Android共享动画兼容实现
- 昂贵的聘礼 POJ