Oracle中表的建立与修改-五种约束
oracle中包括五种约束,包括主键约束(primary key,该属性的值不能为空,不可重复,默认该列自动建立索引),外键约束(foreign k
表的建立
Oracle中包括五种约束,包括主键约束(primary key,该属性的值不能为空,不可重复,默认该列自动建立索引),外键约束(foreign key() references rname,参照完整性约束,该属性的值必须在所对应的关系中存在),非空约束(not null),唯一约束(unique,不可重复,但可以为空,因为在数据库中,该表达式 null=null 的返回结果为unknown),check约束(check(a in(a1,a2,a3))),,如下例
create table r1
( id numeric(15) primary key, //主键约束
name varchar2(15) not null, //非空约束
gender varchar2(2) check(gender in ('M','F','O')), //模拟枚举约束,Oracle中不支持枚举类型
stu_number unique, //禁止重复,但可以为空
foreign key(stu_number) references r0); //外键约束
表的修改
1.增加一个新的属性
alter table r add id varchar2(10);
2.减少一个已经存在的属性
alter table r drop name;
3.修改一个已经存在的属性的限制
alter table test1 modify grade number(5,2) not null;
4.修改一个已经存在的属性的属性名称
alter table test1 rename column id to stu_number;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)
