You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can disable a foreign key constraint during INSERT and UPDATE transactions in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)]. Use this option if you know that new data will not violate the existing constraint or if the constraint applies only to the data already in the database.
5. To re-enable the constraint when desired, reverse the above steps. Select **Enforce Foreign Key Constraint** and select **Yes** from the drop-down menu.
45
+
46
+
6. To trust the constraint by checking the existing data in the foreign key's relationship, select **Check Existing Data on Creation Or Re-Enabling** and select **Yes** from the drop-down menu. This would ensure the foreign key constraint is trusted.
47
+
48
+
- If **Check Existing Data on Creation Or Re-Enabling** is set to **No**, the foreign key does not check existing data when it is re-enabled. The query optimizer is therefore unable to consider potential performance improvements. Trusted foreign keys are recommended because they can be used to simplify execution plans with assumptions based on the foreign key constraint. To check whether foreign keys are trusted in your database, see a sample query later in this article.
5. Verify that the constraintin your environment is both trusted and enabled. If `is_not_trusted`=1, then the foreign key does not check existing data when it is re-enabled or re-created. The query optimizer is therefore unable to consider potential performance improvements. Trusted foreign keys are recommended because they can be used to simplify execution plans with assumptions based on the foreign keyconstraint. Copy and paste the following example into the query window andselect**Execute**.
INNER JOIN sys.objects AS o ON fk.parent_object_id = o.object_id
85
+
WHERE fk.name = 'FK_PurchaseOrderHeader_Employee_EmployeeID';
86
+
GO
87
+
```
88
+
89
+
You should set the foreign keyconstraint to trusted if existing data in the table complies with the foreign keyconstraint. To set the foreign key to trusted, use the following script to trust the foreign keyconstraint again, noting the additional `WITH CHECK` syntax. Copy and paste the following example into the query window andselect**Execute**.
You can view the foreign key attributes of a relationship in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
24
-
25
-
**In This Topic**
26
-
27
-
-**Before you begin:**
28
-
29
-
[Security](#Security)
30
-
31
-
-**To view the foreign key attributes of a specific table, using:**
32
-
33
-
[SQL Server Management Studio](#SSMSProcedure)
34
-
35
-
[Transact-SQL](#TsqlProcedure)
36
-
37
-
## <aname="BeforeYouBegin"></a> Before You Begin
38
-
39
-
### <aname="Security"></a> Security
40
-
41
-
#### <aname="Permissions"></a> Permissions
23
+
24
+
### <aname="Permissions"></a> Permissions
42
25
[!INCLUDE[ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
43
26
44
27
## <aname="SSMSProcedure"></a> Using SQL Server Management Studio
2. In the **Foreign Key Relationships** dialog box, select the relationship with properties you want to view.
51
34
52
35
If the foreign key columns are related to a primary key, the primary key columns are identified in **Table Designer** by a primary key symbol in the row selector.
53
-
36
+
37
+
<aname="TsqlExample"></a>
54
38
## <aname="TsqlProcedure"></a> Using Transact-SQL
55
39
56
40
#### To view the foreign key attributes of a relationship in a specific table
57
41
58
42
1. In **Object Explorer**, connect to an instance of [!INCLUDE[ssDE](../../includes/ssde-md.md)].
59
43
60
-
2. On the Standard bar, click**New Query**.
44
+
2. On the Standard bar, select**New Query**.
61
45
62
-
3. Copy and paste the following example into the query window and click**Execute**. The example returns all foreign keys and their properties for the table `HumanResources.Employee` in the sample database.
46
+
3. Copy and paste the following example into the query window and select**Execute**. The example returns all foreign keys and their properties for the table `HumanResources.Employee` in the sample database.
For more information, see [sys.foreign_keys (Transact-SQL)](../../relational-databases/system-catalog-views/sys-foreign-keys-transact-sql.md) and [sys.foreign_key_columns (Transact-SQL)](../../relational-databases/system-catalog-views/sys-foreign-key-columns-transact-sql.md).
Copy file name to clipboardExpand all lines: docs/t-sql/data-types/ntext-text-and-image-transact-sql.md
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
-
description: "ntext, text, and image (Transact-SQL)"
3
-
title: "ntext, text, and image (Transact-SQL) | Microsoft Docs"
2
+
description: "The ntext, text, and image data types are deprecated data types for storing large non-Unicode and Unicode character and binary data."
3
+
title: "ntext, text, and image (Transact-SQL)"
4
4
ms.custom: ""
5
-
ms.date: "07/22/2017"
5
+
ms.date: "04/13/2022"
6
6
ms.prod: sql
7
7
ms.prod_service: "database-engine, sql-database"
8
8
ms.reviewer: ""
@@ -19,7 +19,6 @@ helpviewer_keywords:
19
19
- "ntext data type"
20
20
- "ntext data type, about ntext data type"
21
21
- "image data type, about image data type"
22
-
ms.assetid: b0d8769c-7598-4f97-8162-ace5f182b5bc
23
22
author: MikeRayMSFT
24
23
ms.author: mikeray
25
24
---
@@ -28,7 +27,8 @@ ms.author: mikeray
28
27
29
28
Fixed and variable-length data types for storing large non-Unicode and Unicode character and binary data. Unicode data uses the UNICODE UCS-2 character set.
30
29
31
-
>**IMPORTANT!****ntext**, **text**, and **image** data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use [nvarchar(max)](../../t-sql/data-types/nchar-and-nvarchar-transact-sql.md), [varchar(max)](../../t-sql/data-types/char-and-varchar-transact-sql.md), and [varbinary(max)](../../t-sql/data-types/binary-and-varbinary-transact-sql.md) instead.
30
+
> [!IMPORTANT]
31
+
> The **ntext**, **text**, and **image** data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use [nvarchar(max)](../../t-sql/data-types/nchar-and-nvarchar-transact-sql.md), [varchar(max)](../../t-sql/data-types/char-and-varchar-transact-sql.md), and [varbinary(max)](../../t-sql/data-types/binary-and-varbinary-transact-sql.md) instead.
32
32
33
33
## Arguments
34
34
**ntext**
@@ -50,12 +50,18 @@ The following functions and statements can be used with **ntext**, **text**, or
> When dropping columns using the deprecated NTEXT data type, the cleanup of the deleted data occurs as a serialized operation on all rows. The cleanup can require a large amount of time. When dropping an NTEXT column in a table with lots of rows, update the NTEXT column to NULL value first, then drop the column. You can run this option with parallel operations and make it much faster.
56
+
54
57
## See also
55
-
[CAST and CONVERT (Transact-SQL)](../../t-sql/functions/cast-and-convert-transact-sql.md)
56
-
[Data Type Conversion (Database Engine)](../../t-sql/data-types/data-type-conversion-database-engine.md)
0 commit comments