mac 打不开 不受信任

介绍 (Introduction)

Intended audience

目标听众

This article is intended for application developers and database administrators who plan to develop, deploy, and/or assess solutions for Microsoft SQL Server on a Microsoft Windows platform.

本文适用于计划在Microsoft Windows平台上开发,部署和/或评估Microsoft SQL Server解决方案的应用程序开发人员和数据库管理员。

Typographical Conventions

印刷约定

Convention Meaning
Stylized Consolas Font Used for blocks of code, commands and script examples.
Text should be interpreted exactly as presented
Consolas Font Used for inline code, commands or examples.
Text should be interpreted exactly as presented
<italic font in brackets> Italic texts set in angle brackets denote a variable requiring substitution for a real value
Italic font Used to denote the title of a book, article, or other publication
Note Additional information or caveats
惯例 含义
程式化的Consolas字体 用于代码块,命令和脚本示例。
文字应完全按原样解释
Consolas字体 用于内联代码,命令或示例。
文字应完全按原样解释
<括号中的斜体> 尖括号中设置的斜体文本表示需要替换为实数值的变量
斜体字体 用于表示书籍,文章或其他出版物的标题
注意 附加信息或警告

Overview

总览

The subject of this article is untrusted foreign keys. Those three words together have a meaning but each word has to be well understood before that. That’s the reason why this article will start with a definitions section where we will define what is a key, what is a foreign key, and how a foreign key can be “untrusted”. Then, we will cover the way to discover and repair untrusted foreign keys for a given database. Finally, we will demonstrate in detail how foreign keys influence the execution of a query when it does not exist, when it exists and is “trusted” and when it exists and is “untrusted”.

本文的主题是不受信任的外键。 这三个词一起具有含义,但在此之前必须先理解每个词。 这就是为什么本文将从“定义”部分开始的原因,其中我们将定义什么是密钥,什么是外键以及如何“不信任”外键。 然后,我们将介绍发现和修复给定数据库的不可信外键的方法。 最后,我们将详细演示外键如何在不存在,何时存在且被“信任”以及何时存在且被“不信任”的情况下影响查询的执行。

定义 (Definitions)

Before going any further, let’s set the base and answer the following questions: « What is a key? », « What is a primary key? » and finally « What is a foreign key? », which is the topic of this article.

在继续进行操作之前,让我们设置基础并回答以下问题:«什么是密钥? »,«什么是主键? »最后,«什么是外键? »,这是本文的主题。

Then, we can talk about what the difference between a trusted and an untrusted foreign key.

然后,我们可以讨论受信任和不受信任的外键之间的区别。

What is a key for a relational table?

关系表的键是什么?

A key is basically an identifier, something that can uniquely identify a record in a relational table. Keys may consist of a single attribute or multiple attributes in combination. Based on the design of a table, there can be more than just one key which identify a record. We will refer to them as candidate keys.

键本质上是一个标识符,它可以唯一地标识关系表中的记录。 键可以包含单个属性,也可以包含多个属性。 根据表的设计,标识记录的键可能不止一个。 我们将它们称为候选键。

Example:

例:

Let’s have a look at the following table. It represents a list of students with 4 columns: a random numeric identifier and the firstname, lastname and sex of the student.

让我们看一下下表。 它代表一个由四列组成的学生列表:一个随机数字标识符以及该学生的名字,姓氏和性别。

StudentID FirstName LastName Sex
5345664 Adam Kent Male
8795165 Jefferson Elias Male
学生卡 名字 性别
5345664 亚当 肯特郡
8795165 杰斐逊 埃里亚斯

There are two candidate keys here: the StudentID, and the combination of FirstName and LastName columns.

这里有两个候选键: StudentID ,以及FirstName 和LastName列的组合。

Let’s add a table with the courses that are given in a particular school. The table will contain a unique identifier for the course, a title and a description.

让我们添加一个表,其中包含特定学校提供的课程。 该表将包含课程的唯一标识符,标题和说明。

CourseId Title CourseDescription
7897 Networks An introductive course on network topologies and standards
8975 Numerical Analysis Basics on numerical analysis.
课程编号 标题 课程说明
7897 网路 网络拓扑和标准入门课程
8975 数值分析 数值分析基础。

There are, also, two candidate keys here: the CourseId column alone and the Title column alone.

这里也有两个候选键:单独的CourseId列和单独的Title列。

What is a primary key for a relational table?

关系表的主键是什么?

The primary key of a relational table is a key that is considered as the most appropriate one among all the acceptable keys for this table. As a key, it can either be a normal attribute that is guaranteed to be unique such as a unique random alpha-numeric identifier or it can be generated by the DBMS.

关系表的主键是被认为是该表所有可接受键中最合适的键。 作为密钥,它可以是保证唯一的常规属性(例如唯一的随机字母数字标识符),也可以由DBMS生成。

In our example, the most appropriate key to identify a given student record is the StudentID column.

在我们的示例中,标识给定学生记录的最合适的键是StudentID列。

What is a foreign key in a relational table?

关系表中的外键是什么?

A foreign key is a basically a reference to another table in a DBMS. It comprises all the key columns composing the primary key of that « foreign » or « parent » table. One who defines a foreign key creates at the same time a referential constraint that checks data provided as a foreign key reference an existing primary key value in the parent table. This constraint must be validated by the DBMS before accepting any kind of modification on the table. So, we can say that a foreign key ensures data integrity.

外键基本上是对DBMS中另一个表的引用。 它包含构成该“ foreign”或“ parent”表的主键的所有键列。 定义外键的人会同时创建一个引用约束,该约束检查作为外键提供的数据是否引用了父表中的现有主键值。 在接受表上的任何类型的修改之前,必须由DBMS验证此约束。 因此,可以说外键可确保数据完整性。

If we carry on with our example, let’s say we have table called StudentEnrollments which keeps track of the enrollments a student has made for current year and his final mark.

如果继续我们的示例,假设我们有一个名为StudentEnrollments的表,该表可以跟踪学生本年度的入学情况及其最终成绩。

StudentId CourseId FinalMark
5345664 7897 16
8795165 8975 9
5345664 7897 18
学生卡 课程编号 最终商标
5345664 7897 16
8795165 8975 9
5345664 7897 18

Here we have two foreign keys:

这里有两个外键:

  1. StudentID column refers to the primary key in the Students table presented previously ;
  2. StudentID列是指前面显示的“ 学生”表中的主键;
  3. CourseId column refers to the primary key in the StudentEnrollments table also presented previously.
  4. CourseId列是指之前也提供过的StudentEnrollments表中的主键。

As a final question for readers, what could possibly be the primary key we can use for this particular table?

对于读者来说,最后一个问题是,我们可以为该特定表使用什么主键?

Answer: the combination of both foreign keys, i.e. (StudentId,CourseId).

答案:两个外键的组合,即( StudentId,CourseId )。

Note
Usually, foreign key references the primary key in a different table. It’s what have been shown in the examples. It’s also good to use it inside the same table. Such a design can be used to create hierarchical ordering in a table. You will find below an example of this: a table called department which has a unique identifier and can be member of another department.

注意
通常,外键引用其他表中的主键。 这是示例中显示的内容。 在同一张表中使用它也很好。 这样的设计可用于在表中创建分层排序。 您将在下面找到一个示例:名为Department的表,该表具有唯一的标识符,并且可以是另一个部门的成员。

DeptId Name HeadOfDept_id ParentDeptId
10 Finance 2 (null)
20 Accounting 23 10
部门编号 名称 HeadOfDept_id ParentDeptId
10 金融 2 (空值)
20 会计 23 10

Here the Finance department has no parent department but has a child department which is the Accounting.

在这里,财务部门没有上级部门,但有一个子部门,即会计部门。

Disabling a foreign key constraint or the way to untrust a foreign key

禁用外键约束或不信任外键的方法

SQL Server allows you to temporarily disable any CHECK or FOREIGN KEY constraint. Common use cases for this particular features are in the area of copying or importing data to a table faster. The process will work for sure, but one who does this operation must ensure that data he’s copying won’t violate those constraints before activate it again.

SQL Server允许您暂时禁用任何CHECK或FOREIGN KEY约束。 此特定功能的常见用例是更快地将数据复制或导入到表中。 该过程肯定会起作用,但是执行此操作的人必须确保要复制的数据在再次激活之前不会违反这些约束。

Here is the syntax to be used to disable then enable a constraint:

这是用于禁用然后启用约束的语法:


ALTER TABLE <SchemaName>.<TableName>NOCHECK CONSTRAINT <ConstraintName>;
ALTER TABLE <SchemaName>.<TableName>WITH { CHECK | NOCHECK }CHECK CONSTRAINT <ConstraintName >;

Specifying WITH CHECK in a statement tells to SQL Server the user wants it to validate the constraint against every single row in the table, then, if successful, enable it.

在语句中指定WITH CHECK告诉SQL Server用户希望它验证对表中每一行的约束,然后,如果成功,则启用它。

In contrast, specifying WITH NOCHECK, which is the default for an existing constraint, means that the constraint is enabled but no validation has been made on it. Even if this mode is faster to run, it can lead to severe side effects on performance: SQL Server doesn’t trust the constraint as it has not validated it. We refer to such a foreign key as an « untrusted foreign key ». As a consequence, the query optimizer won’t use the constraint to do his job…

相反,指定WITH NOCHECK (这是现有约束的默认值)意味着启用了约束,但尚未对其进行验证。 即使此模式运行得更快,也可能导致严重的性能副作用:SQL Server不信任该约束,因为它尚未对其进行验证。 我们将这样的外键称为“不受信任的外键”。 结果,查询优化器将不会使用约束来完成工作……

Human error can occur: one can forget to re-enable the constraint.

可能会发生人为错误:人们可能会忘记重新启用约束。

The proof of this will be given in the demo section.

在演示部分中将提供对此的证明。

检测不受信任的外键并采取适当的措施 (Detect untrusted foreign keys and take the appropriate action)

There is a simple way to detect whether a database contains one or more untrusted foreign keys. It’s simply by querying the sys.foreign_keys view in that database and check the is_not_trusted column. If this column is set to 1, it means the constraint is untrusted.

有一种简单的方法可以检测数据库是否包含一个或多个不受信任的外键。 只需查询该数据库中的sys.foreign_keys视图并检查is_not_trusted列即可。 如果此列设置为1,则表示约束不受信任。

Here is a possible version for the query:

这是查询的可能版本:


SELECT '[' + s.name + '].[' + o.name + '].[' + i.name + ']' AS keyname
FROM    sys.foreign_keys iINNER JOIN sys.objects o ON i.parent_object_id = o.object_idINNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE   i.is_not_trusted = 1AND i.is_not_for_replication = 0AND i.is_disabled = 0

This method is simple but not practical because you must do it against every single database on a SQL Server instance. Instead, we developed a stored procedure that will return a dataset with all the untrusted foreign keys for every database plus the code to solve the issue.

此方法很简单但不切实际,因为您必须针对SQL Server实例上的每个数据库进行此操作。 相反,我们开发了一个存储过程 ,该过程将返回一个数据集,其中包含每个数据库的所有不受信任的外键以及用于解决该问题的代码。

The procedure is called [Administration].[GetUntrustedForeignKeys]. It creates a global temporary table you can then reuse in any other procedure. This table will contain the information described above.

该过程称为[Administration]。[GetUntrustedForeignKeys] 。 它创建一个全局临时表,然后可以在任何其他过程中重用。 该表将包含上述信息。

You will find below its interface. You can specify a database name. If you don’t, it will run against every accessible database on the instance. There are also some parameters that influence the behavior of the procedure.

您将在其界面下方找到。 您可以指定数据库名称。 如果不这样做,它将针对实例上的每个可访问数据库运行。 还有一些参数会影响过程的行为。


PROCEDURE [Administration].[GetUntrustedForeignKeys] (@DbName                     VARCHAR(256) = NULL,@_NoTempTableDropBefore     BIT = 0,@_NoTempTableDropAtTheEnd   BIT = 0,@_NoSelectOnTempTable       BIT = 0
)

The table that is sent back is of the current form:

发送回的表具有当前形式:

 DbName          VARCHAR(256),SchemaName      VARCHAR(256),TableName       VARCHAR(256),ForeignKeyName  VARCHAR(256),DDL2Resolve     VARCHAR(MAX) – computed column

In addition, we defined another stored procedure built on the previous one that effectively runs the code defined in the DDL2Resolve column.

另外,我们定义了另一个存储过程 ,该存储过程建立在前一个存储过程的基础上,该过程有效地运行了DDL2Resolve列中定义的代码。

It’s called [Administration].[RunCheckUntrustedForeignKeys].

称为[Administration]。[RunCheckUntrustedForeignKeys] 。

外键和性能(演示) (Foreign key and performance (Demo))

Let’s begin this section by creating a database for testing and some tables with primary keys. The tables will be the ones shown in the examples: Students, StudentEnrollments and Courses.

让我们从创建用于测试的数据库和一些带有主键的表开始本节。 这些表格将是示例中显示的表格: 学生 , 学生 报名和课程 。

Database Creation Statements.

数据库创建语句。


CREATE DATABASE [TestFK]CONTAINMENT = NONEON  PRIMARY  ( NAME = N'TestFK', FILENAME = N'E:\DBASQL2K12T\TestFK.mdf' , SIZE = 131072KB , MAXSIZE = 16777216KB , FILEGROWTH = 262144KB
)
LOG ON ( NAME = N'TestFK_log', FILENAME = N'L:\DBASQL2K12T\TestFK_log.ldf' , SIZE = 262144KB , MAXSIZE = 16777216KB , FILEGROWTH = 262144KB
);
GOUSE [TestFK]
GOIF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY'
)
BEGINALTER DATABASE [TestFK] MODIFY FILEGROUP [PRIMARY] DEFAULT;
END;
GO

Creation of the Students table.

创建 学生 表。


use TestFK;
GOIF(OBJECT_ID('[dbo].[Students]') IS NULL)
BEGINCREATE TABLE [dbo].[Students] (StudentID   INT IDENTITY(1,1) PRIMARY KEY,FirstName VARCHAR(128) NOT NULL,LastName  VARCHAR(128) NOT NULL,Sex           VARCHAR(6)   NOT NULL);
END;

Creation of the Courses table.

创建 课程 表。


use TestFK;
GOIF(OBJECT_ID('[dbo].[Courses]') IS NULL)
BEGINCREATE TABLE [dbo].[Courses] (CourseID         INT IDENTITY(1,1) PRIMARY KEY,Title             VARCHAR(128) NOT NULL,CourseDescription VARCHAR(MAX));
END;

Creation of the StudentEnrollments table.

创建 StudentEnrollments 表。


use TestFK;
GOIF(OBJECT_ID('[dbo].[StudentEnrollments]') IS NULL)
BEGINCREATE TABLE [dbo].[StudentEnrollments] (StudentID     INT NOT NULL,CourseID       INT NOT NULL,FinalMark      INT NULL);
END;
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[StudentEnrollments]') AND name = N'PK_StudentEnrollments'
)
BEGINALTER TABLE [dbo].[StudentEnrollments] ADD CONSTRAINT [PK_StudentEnrollments] PRIMARY KEY CLUSTERED ([StudentID] ASC,[CourseID] ASC);
END;
GO

As you may have noticed, we haven’t created the foreign key constraints yet. Let’s first get an overview of the way SQL Server handles a query without this foreign key.

您可能已经注意到,我们还没有创建外键约束。 首先让我们概述一下SQL Server在没有此外键的情况下处理查询的方式。

You will find below a query that uses the StudentEnrollments table with the other two tables to get back a view of the name and firstname of a student following a course.

您会在下面找到一个查询,该查询将StudentEnrollments表与其他两个表结合使用,以获取课程学习后学生的姓名和名字的视图。


set statistics io on
set statistics time on
select s.FirstName,s.LastName
from [dbo].[StudentEnrollments] se
inner join [dbo].[Students] son se.StudentID = s.StudentID
inner join [dbo].[Courses] con se.CourseID = c.CourseID ;

Here is its actual execution plan.

这是它的实际执行计划。

Here are statistics on I/O and time:

以下是有关I / O和时间的统计信息:

Let’s now create the foreign key references and see if there is a difference.

现在让我们创建外键引用,看看是否有区别。

Create the Foreign Key constraint to the Courses table.

创建 课程 的外键约束


USE [TestFK]
GOIF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id      = OBJECT_ID(N'[dbo].[FK_StudentEnrollments_Courses]') AND parent_object_id = OBJECT_ID(N'[dbo].[StudentEnrollments]')
)
BEGINALTER TABLE [dbo].[StudentEnrollments]  ADD CONSTRAINT [FK_StudentEnrollments_Courses] FOREIGN KEY([CourseID])REFERENCES [dbo].[Courses] ([CourseID]);
END;
GO

Create the Foreign Key constraint to the Students table.

创建 学生 的外键约束


USE [TestFK]
GOIF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id      = OBJECT_ID(N'[dbo].[FK_StudentEnrollments_Students]') AND parent_object_id = OBJECT_ID(N'[dbo].[StudentEnrollments]')
)
BEGINALTER TABLE [dbo].[StudentEnrollments]  ADD CONSTRAINT [FK_StudentEnrollments_Students] FOREIGN KEY([StudentID])REFERENCES [dbo].[Students] ([StudentID]);
END;
GO

The newer foreign keys change the execution plan of the query we used for test as you will see below. But first, the previous query:

较新的外键将更改我们用于测试的查询的执行计划,如下所示。 但是首先,上一个查询:


set statistics io on
set statistics time on
select s.FirstName,s.LastName
from [dbo].[StudentEnrollments] se
inner join [dbo].[Students] son se.StudentID = s.StudentID
inner join [dbo].[Courses] con se.CourseID = c.CourseID ;

And the resulting actual plan:

以及最终的实际计划:

There is no access to the [dbo].[Courses] table introduced by the inner join due to foreign key addition. As a conclusion, foreign keys may reduce I/O, CPU and time for SELECT queries.

由于添加了外键,无法访问内部联接引入的[dbo]。[课程]表。 结论是,外键可以减少SELECT查询的I / O,CPU和时间。

Now, we will deactivate the foreign keys and insert data into tables then reactivate the foreign key. We will see whether this implies a different behavior or not and check that the foreign keys are untrusted.

现在,我们将停用外键并将数据插入表中,然后重新激活外键。 我们将查看这是否暗示其他行为,并检查外键是否不受信任。


Alter table [dbo].[StudentEnrollments] nocheck constraint [FK_StudentEnrollments_Students];
Alter table [dbo].[StudentEnrollments] nocheck constraint [FK_StudentEnrollments_Courses];

Are those foreign keys untrusted (using the query shown in Section 4).

那些外键不受信任吗(使用第4节中显示的查询)。

The query:

查询:


SELECT '[' + s.name + '].[' + o.name + '].[' + i.name + ']' AS keyname
FROM    sys.foreign_keys iINNER JOIN sys.objects o ON i.parent_object_id = o.object_idINNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE   i.is_not_trusted = 1AND i.is_not_for_replication = 0AND i.is_disabled = 0

Its result:

其结果:

Conclusion: No, the foreign keys are not untrusted at the moment.

结论:不,外键目前并非不受信任。

Let’s populate the tables.

让我们填充表格。


SET NOCOUNT ON ;
DECLARE @RowCount INT;
DECLARE @CurrentSex VARCHAR(6);
DECLARE @RowIdStudent INT;
SET @RowCount = 0;
BEGIN TRANSACTION;
WHILE @RowCount < 21
BEGINif(@RowCount %2 = 0)BEGINSET @CurrentSex = 'Male';END;ELSEBEGINSET @CurrentSex = 'Female';END;insert into [dbo].[Students](FirstName,LastName,Sex)values (REPLICATE('a',@RowCount%6+1),REPLICATE('b',@RowCount%6+1),@CurrentSex);If(@RowCount % 10 = 0) BEGINInsert into [dbo].[Courses] (Title,CourseDescription)values('Course : ' + CONVERT(VARCHAR(20),@RowCount),'Course from ' + CONVERT(VARCHAR(20),@RowCount) );END;SET @RowCount = @RowCount + 1;
END;
COMMIT;insert into StudentEnrollments (StudentID,CourseID
)
select StudentId, 1
from Students where StudentID % 7 = 0
union all
select StudentId, 2
from Students where StudentID % 7 = 1;

Are the foreign keys untrusted now?

现在外键不受信任吗?

No, not yet as shown by the result of our simple detection query:

否,尚未如我们的简单检测查询结果所示:

So, let’s re-enable foreign keys.

因此,让我们重新启用外键。


Alter table [dbo].[StudentEnrollments] check constraint [FK_StudentEnrollments_Students];
Alter table [dbo].[StudentEnrollments] check constraint [FK_StudentEnrollments_Courses];

Are the foreign keys untrusted now?

现在外键不受信任吗?

Definitely, yes as shown by the result of our simple detection query:

肯定的,如我们的简单检测查询结果所示:

Did it change something in the query plan for our test query? Let’s run it again and check its actual execution plan and statistics.

它是否改变了我们测试查询的查询计划? 让我们再次运行它,并检查其实际执行计划和统计信息。

The actual query plan is the following one:

实际的查询计划如下:

While the statistics are:

虽然统计数据是:

Now let’s run our procedure [Administration].[GetUntrustedForeignKeys].

现在,让我们运行过程[Administration]。[GetUntrustedForeignKeys] 。

Here is the T-SQL code to run the procedure for the test database alone:

这是T-SQL代码,仅用于运行测试数据库的过程:


exec SAIDBA.[Administration].[GetUntrustedForeignKeys] @DbName = 'TestFK';

Here is the result given by the procedure:

这是该过程给出的结果:

The DDL2Resolve value for the first untrusted foreign is:

第一个不受信任的外国人的DDL2Resolve值为:


USE [TestFK];
PRINT 'TestFK.dbo.StudentEnrollments(FK_StudentEnrollments_Courses)';
ALTER TABLE [dbo].[StudentEnrollments] WITH CHECK CHECK CONSTRAINT [FK_StudentEnrollments_Courses];

Let’s run both commands as the number of untrusted foreign keys is limited.

让我们运行两个命令,因为不受信任的外键的数量受到限制。

Did we finally solve the problem? Let’s check that there is no untrusted foreign key anymore.

我们终于解决了这个问题吗? 让我们检查一下,不再有不受信任的外键。

The simple audit query:

简单的审计查询:


SELECT '[' + s.name + '].[' + o.name + '].[' + i.name + ']' AS keyname
FROM    sys.foreign_keys iINNER JOIN sys.objects o ON i.parent_object_id = o.object_idINNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE   i.is_not_trusted = 1AND i.is_not_for_replication = 0AND i.is_disabled = 0

Its result:

其结果:

The test query:

测试查询:


set statistics io on
set statistics time on
select s.FirstName,s.LastName
from [dbo].[StudentEnrollments] se
inner join [dbo].[Students] son se.StudentID = s.StudentID
inner join [dbo].[Courses] con se.CourseID = c.CourseID ;

Its actual plan:

其实际计划:

Its execution statistics:

其执行统计:

As the demo comes to its end, there is a final action to do: cleanup.

演示结束时,有最后一个动作要做:清理。

Database Cleanup Statements.

数据库清理语句。


Use [TestFK];
GO
/*
TRUNCATE TABLE Courses;
TRUNCATE TABLE Students;
TRUNCATE TABLE StudentEnrollments;
*/
IF(OBJECT_ID('[dbo].[StudentEnrollments]') IS NOT NULL)
BEGINEXEC sp_executesql N'DROP TABLE [dbo].[StudentEnrollments]';
END;
GO
IF(OBJECT_ID('[dbo].[Students]') IS NOT NULL)
BEGINEXEC sp_executesql N'DROP TABLE [dbo].[Students]';
END;
GOIF(OBJECT_ID('[dbo].[Courses]') IS NOT NULL)
BEGINEXEC sp_executesql N'DROP TABLE [dbo].[Courses]';
END;
GOUSE [master];
GOIF(DB_ID('TestFK') IS NOT NULL)
BEGINEXEC sp_executesql N'DROP DATABASE [TestFK]';
END;
GO

翻译自: https://www.sqlshack.com/managing-untrusted-foreign-keys/

mac 打不开 不受信任

mac 打不开 不受信任_管理不受信任的外键相关推荐

  1. net472无法建立到信任_是否还会信任,那个曾经背叛过自己的人

    对于遭遇过感情背叛的人而言,有很多问题都是共性的.我被问得比较多的一个问题就是:"我到底还应不应该相信ta?"关于这个问题,大多数人一定会给出一个模棱两可的答案,所谓"具 ...

  2. mysql外键约束脚本_如何在MySQL中设置外键约束

    (1) 外键的使用: 外键的作用,主要有两个: 一个是让数据库自己通过外键来保证数据的完整性和一致性 一个就是能够增加ER图的可读性 有些人认为外键的建立会给开发时操作数据库带来很大的麻烦.因为数据库 ...

  3. 数据库mysql表怎么设置外键_如何设置数据库中的外键

    展开全部 创建数据库时就是有主键的创建了主键,但是表之间的关系没有联系,要建数据库关系图只e69da5e887aa62616964757a686964616f31333365653739有主键没有外键 ...

  4. flask sql外键使用_如何在SQL中使用外键?

    flask sql外键使用 Basically, Foreign Key represents relationship between tables. 基本上, 外键代表表之间的关系 . Synta ...

  5. oracle 外键约束不检查历史数据_如何一键禁用Oracle所有外键约束?

    概述 最近在转移数据库,进行数据导入的时候,遇到一件麻烦事,就是表间外键约束的存在,导致insert频频报错,批量执行sql语句又是顺序执行,手动输入的工作量又太大.所以这里考虑是不是可以把外键约束全 ...

  6. mysql外键约束案例_详解MySQL中的外键约束问题

    使用MySQL开发过数据库驱动的小型web应用程序的人都知道,对关系数据库的表进行创建.检索.更新和删除等操作都是些比较简单的过程 .理论上,只要掌握了最常见的SQL语句的用法,并熟悉您选择使用的服务 ...

  7. mysql外键约束的作用_如何在MySQL中设置外键约束以及外键的作用

    1.外键的作用,主要有两个: 一个是让数据库自己通过外键来保证数据的完整性和一致性 一个就是能够增加ER图的可读性 2.外键的配置 1)先创建一个主表,代码如下: #创建表student,并添加各种约 ...

  8. mysql innodb 外键_只有innoDB才允许使用外键

    1.只有InnoDB引擎才允许使用外键,所以,我们的数据表必须使用InnoDB引擎. 2.注意: 1.必须使用InnoDB引擎: 2.外键必须建立索引(INDEX): 3.外键绑定关系这里使用了&qu ...

  9. 在mysql中如何添加外键约束_如何在MySQL中设置外键约束

    (1) 外键的使用: 外键的作用,主要有两个: 一个是让数据库自己通过外键来保证数据的完整性和一致性 一个就是能够增加ER图的可读性 有些人认为外键的建立会给开发时操作数据库带来很大的麻烦.因为数据库 ...

最新文章

  1. 【ios开发/Xcode】实现简易省会问答
  2. python相对路径库_如何最简单、通俗地理解Python的搜索路径、相对路径、绝对路径?...
  3. ubuntu如何设置环境变量,方便log输出路径?(shell文件)
  4. 基于注解的 IOC 配置
  5. DM***时使用OSPF时邻居不断UPDOWN
  6. matlab 离散点差值,散点图的插值方法
  7. python websocket异步高并发_python – WebSocket聊天异步示例崩溃
  8. php逻辑难是难在sql,[实验吧] 所有web writeup
  9. 对于java引用的总结
  10. Codeforces Round #372 (Div. 1) B. Complete The Graph
  11. 什么样的对象会被直接放入老年代
  12. SQL Server 建立索引视图并查看性能状况
  13. Java使用RXTX读取串口
  14. 计算机中英字幕精品教程合集
  15. 取得平均薪水最高的部门的部门编号
  16. 注册一个公众号多少钱_微信公众号申请注册收费吗?要钱吗?多少钱?
  17. Efficientnet笔记:各个框架最适合的图像尺寸
  18. NOIp2017——追求那些我一直追求的
  19. 国内10个最佳PS教程网站
  20. CSS 关键字 initial、inherit 和 unset

热门文章

  1. sql string转number_少用 string.Format
  2. spring-boot-starter-parent的主要作用
  3. [USACO 07DEC]Best Cow Line, Gold
  4. java调用支付宝接口代码介绍
  5. 产品半夜发现bug让程序员加班,程序员应如何回应?
  6. ThinkPHP 多语言的实现
  7. 前缀转后缀(表达式)
  8. JS:ES6-12 模块化
  9. ★LeetCode(371)——两整数之和(JavaScript)
  10. 计算机网络学习笔记(17. 计算机网络作业一)