SQL Constraint/Index

本文介绍了SQL中用于定义业务规则的约束类型,包括外键、非空、唯一和检查约束,并探讨了如何在列级别或表级别定义这些约束。此外,还详细解释了SQL索引的作用及其创建方式,通过索引可以加快对大型表中数据的检索速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、SQL Constraint

Integrity Constraints are used to apply business rules for the database tables.

The constraints available in SQL are Foreign Key, Not Null, Unique, Check.

Constraints can be defined in two ways
1) The constraints can be specified immediately after the column definition. This is called column-level definition.
2) The constraints can be specified after all the columns are defined. This is called table-level definition.

2、SQL Index

Index in sql is created on existing tables to retrieve the rows quickly.

When there are thousands of records in a table, retrieving information will take a long time. Therefore indexes are created on columns which are accessed frequently, so that the information can be retrieved quickly. Indexes can be created on a single column or a group of columns. When a index is created, it first sorts the data and then it assigns a ROWID for each row.

Syntax to create Index:

CREATE INDEX index_name
ON table_name (column_name1,column_name2...);

转载于:https://www.cnblogs.com/xuanyuanchen/p/5934101.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值