Oracle day05 建表_约束
CREATE TABLE [schema.] table (column datatype [DEFAULT expr], ... );
CREATE TABLE table [column(,column...)] AS subquery,
create table emp2 as select * from emp;
- alter table ... add ... : 增加新的列
alter table emp add address varchar()
- alter table ...drop ... : 删除原有的列
alter table emp drop column address
- alter table ...modify ... : 修改字段
alter table emp modify(job varchar())
- drop table : 在基本表不需要时,可以使用语句撤销。
drop table emp cascade constraints
- RENAME : 语句改变表名(视图),要求必须是表(视图)的所有者
RENAME old_name TO new_name
- not null 非空
- unique Key 唯一键
- primary key 主键
- foreign key 外键
- check 自定义检测约束
carete table parent(p1 number primary key); create table child (c1 number primary key ,c2 number references parent(p1));
create table child (c1 nnumber ,c2 number ,primary key(c2), foreign key(c2) references parent(p1));
create table test(id1 number ,id2 number ,primary key(id1,id2));
- 主键从功能上看相当于非空且唯一
- 一个表中只允许一个主键
- 主键是表中能够唯一确定一个行数据的字段
- 主键字段可以是单字段或者是多字段的组合
- Oracle 为主键创建对应的唯一性索引
- primary key(列)主键子句 在表的定义中加上
- primary key主键短语 在主属性的定义之后加上
create table t3( id number(), constraint t3_pk primary key(id) )
- 确保字段值不允许为空
- 只能在字段级定义
CREATE TABLE employees( employee_id number(), name varchar2() not null, salary number(,), hire_date date constraint emp_hire_date_nn not null )
- 唯一性约束条件确保所在的字段或者字段组合不出现重复值
- 唯一性约束条件的字段允许出现空值
- Oracle 将为唯一性约束条件创建对应的唯一性索引
create table employees( id number(), name varchar2() not null unique, email varchar2(), salary number(,), hire_date date not null, constraint emp_email_uk unique(email) );
create table emp3( id number() primary key , age number() check(age > and age <), salary number(,), sex char(), constraint salary_check check(salary>) )
- 实体完整性规则 这条规则要求关系中在组成主键的属性上不能有空值
- 参照完整性规则 这条规则要求“不引用不存在的实体”
- 用户定义的完整性规则 反应了某一具体的应用涉及的数据必须满足的语义要求
alter table tablename
增加
add constraint con_name unique(col)
删除
drop constraint com_name[cascade]
select constraint_name,constraint_type from user_constraints where table_name=upper('sxtstu05')
select constraint_name,constraint_type from user_constraints where owner ='SCOTT'
select constraint_name,column_name from user_cons_columns where table_name =upper('tablename')
Oracle day05 建表_约束的更多相关文章
- oracle基本建表语句
oracle基本建表语句 2010-09-20 10:37:33| 分类: 数据库 | 标签:数据库 oracle |字号 订阅 --创建用户create user han identifie ...
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...
- SQL Server— 存在检测、建库、 建表、约束、外键、级联删除
/******************************************************************************** *主题: SQL Server- 存 ...
- Oracle学习(三)SQL高级--表结构相关(建表、约束)
一.建表语句 CREATE DATABASE(创建数据库) --创建数据库 create database 数据库名字; CREATE TABLE(创建表) --创建表 CREATE TABLE 表名 ...
- oracle的建表语句
oracle数据库的建表语句,具体语法如下: CREATE TABLE tablename (column_name datatype [null,not null], column_name dat ...
- Oracle数据库建表+添加数据练习
SQL脚本: --建表 --student表+注释 create table student( sno ) not null, sname ) not null, ssex ) not null, s ...
- oracle 存储过程 建表插值等
建表.插值的procedure create or replace procedure CREATE_EMP is v_createsql ); v_insertsql ); begin v_crea ...
- oracle得到建表语句
第一种方法是使用工具,如:pl/sql developer,在[工具]--[导出用户对象]出现就可以得到建表脚本. 第二种方法是,sql语句. DBMS_METADATA.GET_DDL包可以得到数据 ...
- Oracle的关于建表,约束,查询等的练习
从建立一个简单表,到实现一些复杂查询的例子, DROP TABLE grade;DROP TABLE item;DROP TABLE sporter;CREATE TABLE sporter( spo ...
随机推荐
- java中int和integer
- react-quill 富文本编辑器 ---- 图片处理
import React,{Component} from 'react'; import ReactQuill,{ Quill } from 'react-quill'; import 'react ...
- 3-3 Hadoop集群完全分布式配置部署
Hadoop集群完全分布式配置部署 下面的部署步骤,除非说明是在哪个服务器上操作,否则默认为在所有服务器上都要操作.为了方便,使用root用户. 1.准备工作 1.1 centOS6服务器3台 手动指 ...
- Java面试题中常考的容易混淆的知识点区别
以下是我收集的Java编程里各种区别,供Java学习爱好者参考,这些区别都是每次Java面试中常考的,大家好好掌握,如有失误请留言指出.想要获取Java详细全套学习资料请到上海尚学堂官网获取. 1.H ...
- Javascript高级编程学习笔记(86)—— Canvas(3)绘制矩形
绘制矩形 矩形是唯一一种可以直接在2D上下文中绘制的形状. 与矩形有关的方法包括: fillRect() strokeRect() clearRect() 上述方法都接收四个参数: 绘制矩形的 X 坐 ...
- centos7启动流程(从加电开始)
图片来自于https://blog.csdn.net/qq_27754983/article/details/75212666 1. UEFI或BIOS启动 服务器加电后,CPU 自动重置成初始状态, ...
- [Swift]LeetCode100. 相同的树 | Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- [Swift]LeetCode216. 组合总和 III | Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- [Swift]LeetCode299. 猜数字游戏 | Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...
- [Swift]LeetCode763. 划分字母区间 | Partition Labels
A string S of lowercase letters is given. We want to partition this string into as many parts as pos ...