sql 复合键_SQL复合键
sql 复合键
In a real-time situation, there can be scenarios when one column is not good enough to uniquely identify a row. In such scenarios, we use a combination of columns to uniquely identify a row.
在实时情况下,可能会出现一列不足以唯一标识一行的情况。 在这种情况下,我们使用列的组合来唯一地标识一行。
SQL复合键 (SQL Composite Key)
SQL composite key is a combination of two or more columns in a table that is used to uniquely identify a row. The combination of the columns guarantees uniqueness.
SQL复合键是表中两个或更多列的组合,用于唯一标识一行。 列的组合保证了唯一性。
We will try to understand how to create a composite key in the below-mentioned databases.
我们将尝试了解如何在下面提到的数据库中创建组合键。
- MySQLMySQL
- SQLServerSQL服务器
- PostgreSQLPostgreSQL
MySQL复合键 (MySQL Composite Key)
Syntax: –
句法: -
CREATE TABLE table_name
(COL1 datatype,
COL2 datatype, COLn datatype
PRIMARY KEY (COL1, COL2));
In the syntax above, we can see that the primary key is a combination of two columns.
在上面的语法中,我们可以看到主键是两列的组合。
Let us create a table with a composite primary key.
让我们创建一个带有复合主键的表。
CREATE TABLE Employee(
employee_nointeger,
employee_name character(50),
employee_city character(35),
employee_phn numeric,PRIMARY KEY (employee_no,employee_phn));
In the table above, we are creating the primary key using two columns – employee_no and employee_phn.
在上表中,我们使用两列创建主键-employee_no和employee_phn。
Post-execution of the above query check the table property. The following screen will appear.
执行以上查询后,检查表属性。 将出现以下屏幕。
MySQL Composite Primary Key
MySQL复合主键
PostgreSQL复合密钥 (PostgreSQL Composite Key)
Syntax: –
句法: -
CREATE TABLE table_name
(COL1 datatype,
COL2 datatype, COLn datatype
PRIMARY KEY (COL1, COL2));
In the syntax above, we can see that the primary key is a combination of two columns.
在上面的语法中,我们可以看到主键是两列的组合。
Let us create a table with a composite primary key.
让我们创建一个带有复合主键的表。
CREATE TABLE Employee(
employee_no integer,
employee_name character(50),
employee_city character(35),
employee_phn numeric,PRIMARY KEY (employee_no,employee_phn));
In the table above, we are creating a primary key using two columns – employee_no and employee_phn.
在上表中,我们使用两列创建主键-employee_no和employee_phn。
Post-execution of the above query at PGAdmin, the following screen will appear.
在PGAdmin上执行上述查询后,将出现以下屏幕。
PostgreSQL Composite Primary Key
PostgreSQL复合主键
SQL Server复合键 (SQL Server Composite Key)
Syntax: –
句法: -
CREATE TABLE table_name
(COL1 datatype,
COL2 datatype, COLn datatype
PRIMARY KEY (COL1, COL2));
In the syntax above, we can see that the primary key is a combination of two columns.
在上面的语法中,我们可以看到主键是两列的组合。
Let us create a table with a composite primary key.
让我们创建一个带有复合主键的表。
CREATE TABLE Employee(
employee_no integer,
employee_name character(50),
employee_city character(35),
employee_phn numeric,PRIMARY KEY (employee_no,employee_phn));
Post-execution of the above query at SQL server. The following screen will appear.
在SQL Server上执行以上查询。 将出现以下屏幕。
SQLServer Composite Primary Key
SQLServer复合主键
摘要 (Summary)
SQL composite key is used only when a column is not suitable for uniquely identifying a row.
仅当列不适合唯一标识行时,才使用SQL复合键。
翻译自: https://www.journaldev.com/30173/sql-composite-key
sql 复合键
sql 复合键_SQL复合键相关推荐
- sql主键_SQL主键
sql主键 In a world driven with data all over, it is very easy to get duplicate data. The nightmare of ...
- sql外键_SQL外键
sql外键 In this article let us review different ways to create a SQL foreign key, rules on updates and ...
- 数据库原理与应用(SQL Server)教程 主键、外键以及联合主键、复合主键和设置种子数目和增量
文章目录 前言 一.主键.联合主键和复合主键 (一)主键 (二)联合主键 (三)复合主键 二.外键.设置种子数目和增量 (一)外键的概念 (二)添加外键 (三)设置种子数目和增量 结语 前言 这篇文章 ...
- sql 复合主键 联合主键_学习SQL:主键
sql 复合主键 联合主键 If you've already worked with databases, then you could hardly miss the term – Primary ...
- 超键、候选键、主键、外键、联合主键、复合主键
首先看看各种键的定义: 超键(super key):在关系中能唯一标识元组的属性集称为关系模式的超键(只要有一个键唯一,再随便组其他的键,合起来叫主键) 候选键(candidatekey):不含有多余 ...
- 对逻辑主键、业务主键和复合主键的思考
这几天对逻辑主键.业务主键和复合主键进行了一些思考,也在网上搜索了一下相关的讨论,相关讨论可以看最下面的参考链接.下面是自己基于 SQL Server 做的一些总结,其他数据库(Oracle.MySQ ...
- mysql复合主键做外键,mysql – 使用复合主键作为外键
如何将复合主键用作外键?看起来我的尝试不起作用. create table student ( student_id varchar (25) not null , student_name varc ...
- oracle联合主键效率,Oracle主键与复合主键的性能分析
总结: 1.主键和复合主键,查询性能相同(索引高度相同,恰当的运用索引). 2.主键和复合主键,(update,insert)性能不同(因为复合主键会用更多的块来创建索引,所以update,inser ...
- mysql 联合主键重复数据库_联合主键和复合主键有什么区别
联合主键和复合主键有什么区别 发布时间:2020-07-11 09:52:20 来源:亿速云 阅读:171 作者:Leah 这期内容当中小编将会给大家带来有关联合主键和复合主键有什么区别,文章内容丰富 ...
最新文章
- php禁止指定ip访问网站,方法分享:如何利用.htaccess禁止某个IP访问网站
- 博后招募 | 西湖大学工学院蓝振忠深度学习实验室招募博士后
- gitlab常规维护命令
- 【TEG第7年】这里有你和你的永不妥协
- python request.post 字典参数以json_Python requests.post方法中data与json参数区别详解
- java中的Queue队列的用法
- 更换mysql_这些被你忽视的MySQL细节,可能会让你丢饭碗!
- linux 主机大华 摄像头,linux设备上的Onvif 实现21:解决大华摄像头无法使用问题...
- 固定 顶部_抗拉固定球铰支座优点与施工步骤
- Linux系统手动安装rpm包依赖关系分析(以Kernel升级为例)
- VCPU shutdown request
- 高拍仪二次开发(多浏览器,BS,Web)样例
- 实现spring+mybatis+uncode dal,应用自动切换连接数据库
- 智牛股_第6章_Mybatis Generator代码生成器
- 我的Lenovo ThinkPad R60e 键盘按键失灵!
- OEM,ODM,OBM,JDM概念
- Win7无线网络共享教程:解决所有问题
- 与文本内容无关的说话人识别概述——从特征到超矢量
- Maven 项目查找 jar 包是由哪个依赖引入的
- win10如何更改计算机的用户名称,win10账户名修改,详细教您win10怎么更改账户名称...
热门文章
- 【Java】【编译】javac编译源代码时,若源文件使用了别的java源代码的函数,javac会自动关联。...
- (安卓)一键锁屏 ---亲测!
- 一步步学习微软InfoPath2010和SP2010--第十二章节--管理和监控InfoPath Form Services(IPFS)(4)--监控含图片控件的Products表单...
- 分享40套非常精美的免费 PSD 网页图标素材
- [转载] Python_range()_逆序
- [转载] python解析返回结果_python:解析requests返回的response(json格式)说明
- [转载] Python杂谈 | (6) numpy中array()和asarray()的区别
- [转载] (三)Python关键字和内置函数
- MySQL之存储引擎,数据类型,约束条件
- elasticsearch监控平台cerebro-0.8.3 相关操作