- SQL - Discussion
- SQL - Useful Resources
- SQL - Useful Functions
- SQL - Quick Guide
- SQL - Questions and Answers
- SQL - Datatype Functions
- SQL - Conversion Functions
- SQL - JSON Functions
- SQL - Cursor Functions
- SQL - Logical Functions
- SQL - Statistical Functions
- SQL - Text & Image Functions
- SQL - Numeric Functions
- SQL - Aggregate Functions
- SQL - String Functions
- SQL - Date Functions
- SQL - Database Tuning
- SQL - IN vs EXISTS
- SQL - Group By vs Order By
- SQL - Common Table Expression
- SQL - Cursors
- SQL - Date & Time
- SQL - Auto Increment
- SQL - Using Sequences
- SQL - Handling Duplicates
- SQL - Sub Queries
- SQL - Transactions
- SQL - NULL Values
- SQL - Stored Procedures
- SQL - Default Constraint
- SQL - Check Constraint
- SQL - Null Functions
- SQL - Min & Max
- SQL - Hosting
- SQL - Injection
- SQL - Comments
- SQL - Wildcards
- SQL - Non-Clustered Index
- SQL - Clustered Index
- SQL - Unique Index
- SQL - Primary Key
- - 工会诉Join
- SQL - Inner Join
- SQL - Using Joins
- SQL - Aliases
- SQL - EXCEPT Operator
- SQL - INTERSECT Operator
- SQL - UNION vs UNION ALL
- SQL - UNION Operator
- SQL - BETWEEN Operator
- SQL - NOT NULL
- SQL - IS NOT NULL
- SQL - IS NULL
- SQL - NOT EQUAL
- SQL - NOT Operator
- SQL - CASE
- SQL - EXISTS Operator
- SQL - ANY, ALL Operators
- SQL - IN Operator
- SQL - LIKE Operator
- SQL - BOOLEAN (BIT) Operator
- SQL - AND & OR
- SQL - Having Clause
- SQL - Group By Clause
- SQL - Order By Clause
- SQL - Distinct Clause
- SQL - Top Clause
- SQL - Where Clause
- SQL - Rename Views
- SQL - Drop Views
- SQL - Update Views
- SQL - Create Views
- SQL - Sorting Results
- SQL - Delete Query
- SQL - Update Query
- SQL - Insert Into Select
- SQL - Select Into
- SQL - Select Query
- SQL - Insert Query
- SQL - Constraints
- SQL - Delete Table
- SQL - Drop Table
- SQL - Alter Tables
- SQL - Temporary Tables
- SQL - Clone Tables
- SQL - Truncate Table
- SQL - Rename Table
- SQL - Show Tables
- SQL - Create Table
- SQL - Backup Database
- SQL - Show Database
- SQL - Rename Database
- SQL - Select Database
- SQL - Drop Database
- SQL - Create Database
- SQL - Expressions
- SQL - Operators
- SQL - Data Types
- SQL - Syntax
- SQL - Databases
- SQL - RDBMS Concepts
- SQL - Overview
- SQL - Home
5. 图瓦卢
- 页: 1
- 页: 1
- 结构-创建指数
- 页: 1
- 页: 1
- 页: 1
- SQL - Foreign Key
- 文 件
- ∗ E/CN.6/2009/1。
- 页: 1
- 页: 1
- 文 件
- 页: 1
- 页: 1
- 文 件
- 页: 1
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SQL - Alternate key
表格的替代关键内容是目前尚未选定作为表格主要关键内容的候选人。 这些是次要候选人钥匙,可用于在表格中独一无二地识别图(或记录)。
没有任何具体询问或提要在表格中确定备用钥匙。 这只是一栏,是第二栏,可以选择为主要候选人。
A KEY plays an important role in a relational database. It is an attribute or set of attributes, that helps us to identify the unique row(or record) in a table. It also estabpshes the relationship among tables.
Let us suppose we have a table named CUSTOMERS with various fields pke ID, Name, Mobile, address, etc. In this table ID and Mobile are treated as candidate keys. By using these two fields we can get the unique record from the Customer s table. Among them, one is treated as the primary key and another key is known as the alternate key of the Customer s table.
让我们以适当的图表理解——
在上述客户表格中,“身份识别”栏和“流动”栏被称为候选人钥匙。 因此,如果你把“ID”一栏视为主要钥匙,那么“Mobile_no”一栏即为客户表格的备用钥匙。
Even though alternate keys are not primary keys, they contain some important properties/features of their own. They are psted below.
The alternate key does not allow duppcate values.
A table can have more than one alternate keys.
The alternate key can contain NULL values unless the NOT NULL constraint is set exppcitly.
All alternate keys can be candidate keys, but all candidate keys can not be alternate keys. As a primary key, which is also a candidate key, can not be considered as an alternate key.
Keys in a table
下表所列关键人物名单如下:
Candidate key
Primary key
Alternate key
Foreign Key
Candidate Key
A 关键是用于独一无二地确定表格记录的超级钥匙。 它可以是一个单一的领域或多个领域。 主要关键人物、候补钥匙、表格中的外国关键人物都是候选人的关键。
Primary Key
A Primary Key is a main key that is used to retrieve records from a table. It is a single column or field in a table that uniquely identifies each record in a database table.
可使用中文本不适用。 关键词,同时利用国家扫盲十年声明编制一个表格。
Syntax
CREATE TABLE COLUMN_NAME1, COLUMN_NAME2… PRIMARY KEY(COLUMN_NAME));
Alternate Key
在数据库表上没有星号。
Foreign Key
表格的主要将在另一个表中填入Foreign key。 在将这些表格插入价值的同时,主要领域的价值必须与外国关键领域的价值观相匹配;否则,外国关键一栏将不接受INSERT/b>。 查询和投出错误。
在服务器中,在表格中建立一个外国关键领域的辛迪加——
CREATE TABLE TABLE_2(COLUMN_NAME FOREIGN KEY REFERENCES TABLE_1(COLUMN_NAME));
让我们看到一个例子,显示特定钥匙的使用情况,并表明可以被视为编制表格中一个替代钥匙的领域。
Example
在以下例子中,我们正在建立一个表格名称:CUSTOMERS,在“Q”号声明下显示的“Q”数据库中各个领域——
CREATE TABLE CUSTOMERS( ID INT, NAME VARCHAR (20), AGE INT, ADHARCARD_ID BIGINT, MOBILE_NO BIGINT, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY(ID) );
现在请在Customer s表格中添加一些记录,使用INSERT说明如下:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADHARCARD_ID,MOBILE_NO, ADDRESS,SALARY) VALUES (1, Ramesh , 32, 901234984567, 9021345687, Ahmedabad , 2000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADHARCARD_ID,MOBILE_NO,ADDRESS,SALARY) VALUES (2, Khilan , 25, 911232495457,9021345687, Delhi , 1500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADHARCARD_ID,MOBILE_NO,ADDRESS,SALARY) VALUES (3, Kaushik , 23, 912232425416, 9824434518, Kota , 2000.00);
现在请使用SlectT表显示表格数据如下:
SELECT * FROM CUSTOMERS;
下表将列出:
+----+---------+------+--------------+------------+-----------+---------+ | ID | NAME | AGE | ADHARCARD_ID | MOBILE_NO | ADDRESS | SALARY | +----+---------+------+--------------+------------+-----------+---------+ | 1 | Ramesh | 32 | 901234984567 | 9021345687 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | 911232495457 | 9021345687 | Delhi | 1500.00 | | 3 | Kaushik | 23 | 912232425416 | 9824434518 | Kota | 2000.00 | +----+---------+------+--------------+------------+-----------+---------+ 3 rows in set (0.00 sec)
In the above table, the keys are set as follows −
但是,为了显示Foreign key,我们需要两个表格。 下面是关于创建另一个表格ORDERS的问询,该表是作为CUSTOMER_ID的外国钥匙。
CREATE TABLE ORDERS ( OID INT NOT NULL, DATE DATETIME, CUSTOMER_ID INT FOREIGN KEY REFERENCES CUSTOMERS(ID), AMOUNT DECIMAL, PRIMARY KEY (ID) );
采用INSERT声明,在本表中插入以下数值:
INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (102, 2009-10-08 00:00:00 , 3, 3000.00); INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (101, 2009-11-20 00:00:00 , 2, 1560.00); INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (100, 2009-10-08 00:00:00 , 1, 1500.00);
To display the ORDERS table, we can use the following query −
SELECT * FROM ORDERS;
该表将显示如下:
+-----+---------------------+-------------+---------+ | OID | DATE | CUSTOMER_ID | AMOUNT | +-----+---------------------+-------------+---------+ | 100 | 2009-10-08 00:00:00 | 1 | 1500.00 | | 101 | 2009-11-20 00:00:00 | 2 | 1560.00 | | 102 | 2009-10-08 00:00:00 | 3 | 3000.00 | +-----+---------------------+-------------+---------+
The foreign key will be referenced to the ID column in the Customers table above.
我们可以看到Foreign key field of ORDERS。 表格将符合CUSTOMERS表主要领域的数值。
Rules to be followed for alternate keys
下面列出在将记录列入表格时应当遵循的候补钥匙规则清单。
Alternate key values should be unique.
Alternate key can not be NULL.