- 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 - Primary Key
www.un.org/spanish/ga/president 它是最合适的候选人,是任何表格的主要关键。
表格只能有一个中程,其中可包括单一或多个领域。 当多个领域被用作主要钥匙时,它们被称为复合钥匙。
A KEY is a field or combination of fields in a database table, that is used to retrieve and sort rows based on certain criteria. Keys are defined to speed up data access and, in many cases, to create a relationship between tables.
让我们说,你正在开发一个名为大学管理系统的申请,以便在一个组织内处理所有数据。 在为学生或教师设计数据库表时,可提供student_id或faculty_id。 第1栏/点是主要钥匙,因此阻止你将同一个斜线分配给多个学生/学生。 这是对初级钥匙的实时使用。
下面是客户表格的图表,可以让你知道主要钥匙在表格中究竟是什么?
我们能够做到 客户_Id。 以上栏目 表格 a Primary Key,利用这一钥匙,我们可以检索任何客户独特的记录。
Creating a Primary Key
To add the primary key constraint on a particular column of a table, you need to specify the name of that column as PRIMARY KEY(COLUMN_NAME), and this column name will be considered as a primary of that table
这里是 PRIMEY的关键要点。
它只具有独特的价值。
It can not be null.
一个表格只能有一个主轴。
主要关键长度不能超过900个。
Syntax
Following is the syntax to define a column of a table as a primary key −
CREATE TABLE TABLE_NAME (COLUMN_NAME NOT NULL PRIMARY KEY(COLUMN_NMAE));
Example
在以下例子中,我们试图在数据库中建立一个名称为CUSTOMERS的桌子。 在制作表格时,我们将在<><>>>的栏目上添加“临时关键”栏。
CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
Output
下面是上述表格的产出:
(0 rows affected)
Verification
由于我们知道主要价值必须是独一无二的,因此你不能用同一身份加入记录。 在此,我们将通过添加带有重复识别价值的记录来核实在ID栏上产生的限制。
首先,请在CUSTOMERS表中插入一个记录。
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, kaushik , 23, Kota , 2000.00 );
现在,请在same ID上添加一个记录——
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, Chaitap , 25, Mumbai , 6500.00 );
如上文所述,如果任何外地/栏目在数据库表中被定义为主要人物,则两个记录不能具有该栏/外地的相同价值。 因此,第二点加上说明会产生以下错误。
Result: ERROR 1062 (23000): Duppcate entry 3 for key customers.PRIMARY
Verification
同样,主要一栏不能包含无效价值。 此处使用INSERT 我们将努力通过NUL。 基本关键一栏的价值。 让我们添加一份具有国际发展价值的客户记录,使其无效。
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (null, Komal , 22, MP , 4500.00 );
In the above created table CUSTOMERS, we made the column name ID as the primary key, so we can’t insert a record with the ID value NULL. Therefore, the INSERT statement generates the following error.
Result: ERROR 1048 (23000): Column ID cannot be null
Dropping a Primary Key
If you can add a Primary Key Constraint to a column in the table, you can also drop it. This is done by using the ALTER TABLE DROP statement.
Syntax
您可放弃 法定关键。 使用ALTER的表格一栏的限制 下表:
ALTER TABLE TABLE_NAME DROP PRIMARY KEY;
Example
让我们考虑CUSTOMERS。 表格:我们对一个名为ID的栏目造成主要制约因素。 您可以执行以下声明,将这一限制从ID栏中删除:
ALTER TABLE CUSTOMERS DROP PRIMARY KEY;
Output
以上查询得出以下产出:
(0 rows affected)
Verification
由于我们从ID栏中删除了法定关键,我们现在可以用同样的识别符号插入多个记录。 现在,请将4个记录列入同一索引——
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, Ramesh , 32, Ahmedabad , 2000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, Khilan , 25, Delhi , 1500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, kaushik , 23, Kota , 2000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, Chaitap , 25, Mumbai , 6500.00 );
如果你核实该表的内容,你可以找到所有有same ID的记录。
select * from Customers;
+----+----------+-----+-----------+---------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+---------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 1 | Khilan | 25 | Delhi | 1500.00 | | 1 | kaushik | 23 | Kota | 2000.00 | | 1 | Chaitap | 25 | Mumbai | 6500.00 | +----+----------+-----+-----------+---------+Advertisements