English 中文(简体)
A. 单一物质和复合 ql服务器
原标题:Difference Between Unique And Composite Primary key In sql server

我想知道,在服务器库中,独一无二的关键和综合主要关键之间的区别是什么。

根据民团的数据:

UNIquest制约因素在数据库表中独特地确定了每个记录。

UNIquest和PRIMaire KEY制约因素为一栏或一栏提供了独一无二的保障。

真正的关键制约因素必然会对其产生一种限制。

请注意,你可以按桌上提出许多限制,但每张表格中只能有一个初步的KEY制约因素。

我们可以通过利用这一点来创造综合的主要关键:

CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
UNIQUE (P_Id)
)

用于综合主要合成物:

CREATE TABLE Persons
(
P_Id int,
C_Id int,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
Primary Key (P_Id,C_Id)
);
问题回答

UNIquest制约因素在数据库表中独特地确定了每个记录。 这为一栏或一栏的独特性提供了保障。 我们可以确定(点)一行。

临时KEY因违约而受限制。

在一些表格中,没有一栏具有独特价值,可以确定行文。 在这种情况下,使用COMOSITE KEY。 在这种情况下,将两栏或两栏以上合并,使这种组合具有独特性。

As you said yourself, the only difference between a unique and a primary key is that there may only be 1 primary key on a table while it can have more unique keys.
Furthermore, the values of a primary key may not be null.
Both unique- and primary keys can be composed of multiple columns (composed key).

By the ways, in your example you had a unique key on the P_Id column and a composed primary key that includes that very same column.
This has no sense.
I would suggest to create only a simple primary key on that P_Id column.

复合钥匙由一栏以上组成

主要关键因素使表上第二行的数值与关键栏值相同。

主要钥匙可以形成一栏和一栏以上。 因此,主要钥匙也可以被定义为复合钥匙。

The primary key does not accept the any duplicate and NULL values. A primary key of one table can be referenced by foreign key of another table. A table can have more than one unique key unlike primary key. Unique key constraints can accept only one NULL value for column. Unique constraints are also referenced by the foreign key of another table. A composite key is having two or more attributes that together can uniquely identify a tuple in a table. Such a key is also known as Compound Key, where each attribute creating a key is a foreign key in its own right.

Composite Key - Combine multi一栏,作为保持其集体独一无二性的唯一主要关键部分,一栏将一栏合并,单独列出其非unique(例如) 在一所学校里,我们有一大批学生的名字是Ram,但只有一名学生与DOB、父母姓名和其他制约因素有关系,这可以通过使用综合钥匙来实现。

Unique Key——另一方面,维持一个单列/多栏的UNIquest。

Primary Key - Single Unique Primary Key for the table.

注:我们可以在每一栏(Composite Key)中重复数值,但整体而言,它必须是UNIquest/strong>。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...