数据库常用DDL
来源:互联网 发布:织梦cms移动版静态化 编辑:程序博客网 时间:2024/05/17 23:40
常用DDL
DDL: 数据定义语言(create 建表等, alter 修改结构, drop 删除表等等)
1)create
创建表,建表时可以同时为字段添加相应的约束
create table employee( empno number(4) not null, --员工编号, not null表示该字段不能为空 ename varchar2(20) not null, --员工姓名 job varchar2(9), mgr number(4), --经理编号 hiredate date, --入职日期 sal number(7,2), --薪水 comm number(7,2), --佣金、提成 deptno number(2) --部门编号)--建表时一起加约束create table emp2( empno number(4) not null primary key, --员工编号, not null表示该字段不能为空 ename varchar2(20) not null unique, --员工姓名 job varchar2(9), mgr number(4), --经理编号 hiredate date default sysdate, --入职日期 sal number(7,2) check(sal>500.0), --薪水 comm number(7,2), --佣金、提成 deptno number(2) --部门编号)create table emp3( empno number(4) not null, --员工编号, not null表示该字段不能为空 ename varchar2(20) not null, --员工姓名 job varchar2(9), mgr number(4), --经理编号 hiredate date, --入职日期 sal number(7,2) check(sal>500.0), --薪水 comm number(7,2), --佣金、提成 deptno number(2), --部门编号 constraint pk_emp3_empno primary key(empno), constraint un_emp3_ename unique(ename), --constraint df_emp3_hiredate (hiredate default sysdate), constraint chk_emp3_sal check (sal>500.0))
2)alter 修改表结构等
--DDL修改表结构alter table employee add(tel varchar2(13)); --增加一个新列 alter table employee modify tel varchar2(11); --修改列的宽度alter table employee rename column tel to mobile; --重命名列名alter table emp rename to employee; --重命名表名alter table employee drop column mobile; --删除表的列
--DDL修改表结构alter table employee add(tel varchar2(13)); --增加一个新列 alter table employee modify tel varchar2(11); --修改列的宽度alter table employee rename column tel to mobile; --重命名列名alter table emp rename to employee; --重命名表名alter table employee drop column mobile; --删除表的列
/*为表添加主键约束。语法: alter table 表名 add constraint 约束名 primary key(主键字段名);*/alter table employee add constraint pk_employee_empno primary key(empno);/*为表添加唯一约束。 语法: alter table 表名 add constraint 约束名 unique(字段名);*/alter table employee add constraint un_employee_ename unique(ename);/*为表添加默认约束。 语法: alter table 表名 modify (字段名 default 默认值);*/alter table employee modify (hiredate default sysdate);/*为表添加检查约束。 语法: alter table 表名 add constraint 约束名 check(sal>=1000 and sal<=15000)*/alter table employee add constraint chk_employee_comm check(comm>=0.0 and comm<=10000.0);--alter table 表名 drop constraint 约束名
3)drop删除表等
drop table employee;
0 0
- 数据库常用DDL
- 常用的数据库中的ddl
- MySql数据库常用DDL语句 | 黄乔国PHP
- Oracle数据库语法之【DDL】常用汇总-【更新】
- 数据库_MySQL_常用DDL、DML、DCL语言整理(附样例)
- 常用DDL语句
- 常用Oracle DDL
- MySQL常用DDL
- orcale 常用DDL 语句
- MySQL常用DDL
- 常用oracle DDL语句
- MySQL常用DDL
- MySQL常用DDL
- 常用SQL DDL语句
- 常用的DDL语句
- 常用DDL语句汇总
- oracle常用DDL语句
- 常用DDL语句
- html5 标签img学习(待更新)
- UnityVS(Visual Studio Tools For Unity)的安装与使用
- android HandlerThread源码解析
- CSU 1552( MiLLer_Rabin+二分图匹配)
- Install ffmpeg
- 数据库常用DDL
- leetcode笔记:Word Ladder
- [Linux] date的用法及格式化
- Struts2.properties属性文件中的devModel和DynamicMethodInvocation。。。Action中servlet对象的获取
- 并查集基础
- linux下零拷贝技术
- 建表 PowerDesigner使用
- C++Windows下SQLite简单封装
- 计算群论软件比较(GAP4、Magma2、Matlab7/Maple8、PARI/GP)