SQLServer2005/在被引用表 'tab2' 中没有与外键 'f
SQLServer2005/在被引用表 'tab2' 中没有与外键 'fk_tab12tab2' 中的引用列列表匹配的主键或候选键。 这个原因是由于表2被引用的的字段不是候选键或者不是主键,说白了就是确保它是唯一的; CREATE TABLE tab1 ( id int, name varchar(30) ); CREATE TABLE t
SQLServer2005/在被引用表 'tab2' 中没有与外键 'fk_tab12tab2' 中的引用列列表匹配的主键或候选键。
这个原因是由于表2被引用的的字段不是候选键或者不是主键,说白了就是确保它是唯一的;
CREATE TABLE tab1
( id int,
name varchar(30)
);
CREATE TABLE tab2
(
name2 VARCHAR(30)
);
--将表tab2的字段name2作为tab1的外键,
ALTER TABLE tab1 ADD CONSTRAINT fk_tab12tab2 FOREIGN KEY (name) REFERENCES tab2(name2);
--错误信息
/*消息 1776,级别 16,状态 0,第 1 行
在被引用表 'tab2' 中没有与外键 'fk_tab12tab2' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,第 1 行
无法创建约束。请参阅前面的错误消息。
*/
//将字段name2作为主键,如果按照如下方式建立表,那么结果通过。
CREATE TABLE tab2
(
name2 VARCHAR(30) PRIMARY KEY
);
--命令已成功完成。
//将字段name2设为唯一,
CREATE TABLE tab2
(
name2 VARCHAR(30) UNIQUE
);
那么结果也是通过的。
--命令已成功完成。
如果要删除约束:
ALTER TABLE tab1 DROP CONSTRAINT fk_tab12tab2

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In iOS 17 and macOS Sonoma, Apple has added new formatting options for Apple Notes, including block quotes and a new Monostyle style. Here's how to use them. With additional formatting options in Apple Notes, you can now add block quotes to your notes. The block quote format makes it easy to visually offset sections of writing using the quote bar to the left of the text. Just tap/click the "Aa" format button and select the block quote option before typing or when you are on the line you want to convert to a block quote. This option applies to all text types, style options, and lists, including checklists. In the same Format menu you can find the new Single Style option. This is a revision of the previous "equal-width"

C++ is a popular programming language, but during use, the compilation error "undefined reference" often occurs, which brings a lot of trouble to program development. This article will discuss the solution to the "undefined reference" error from both the cause and the solution. 1. Cause of error When the C++ compiler compiles a source file, it will be divided into two stages: the compilation stage and the link stage. The compilation phase converts the source code in the source files into assembly code, while the linking phase combines different source files into an executable file.

The benefits of functions returning reference types in C++ include: Performance improvements: Passing by reference avoids object copying, thus saving memory and time. Direct modification: The caller can directly modify the returned reference object without reassigning it. Code simplicity: Passing by reference simplifies the code and requires no additional assignment operations.

References and pointers in C++ are both methods of passing function parameters, but there are differences. A reference is an alias for a variable. Modifying the reference will modify the original variable, while the pointer stores the address of the variable. Modifying the pointer value will not modify the original variable. When choosing to use a reference or a pointer, you need to consider factors such as whether the original variable needs to be modified, whether a null value needs to be passed, and performance considerations.

C++ is an object-oriented programming language, and its flexibility and power often provide programmers with great help. However, precisely because of its flexibility, it is difficult to avoid various small errors when programming. One of the most common mistakes is that when a function returns a pointer or reference, it cannot return a local variable or temporary object. So how to deal with this problem? This article will introduce the relevant content in detail. The cause of the problem is that in the C++ language, local variables and temporary objects are dynamically allocated during the running of the function. When the function ends, these local variables and temporary

By using pointers and references, memory usage in C++ can be optimized: Pointers: store addresses of other variables and can point to different variables, saving memory, but may generate wild pointers. Reference: Aliased to another variable, always points to the same variable, does not generate wild pointers, and is suitable for function parameters. Optimizing memory usage can improve code efficiency and performance by avoiding unnecessary copies, reducing memory allocations, and saving space.

What is AMP Coin? The AMP token was created by the Synereo team in 2015 as the main trading currency of the Synereo platform. AMP token aims to provide users with a better digital economic experience through multiple functions and uses. Purpose of AMP Token The AMP Token has multiple roles and functions in the Synereo platform. First, as part of the platform’s cryptocurrency reward system, users are able to earn AMP rewards by sharing and promoting content, a mechanism that encourages users to participate more actively in the platform’s activities. AMP tokens can also be used to promote and distribute content on the Synereo platform. Users can increase the visibility of their content on the platform by using AMP tokens to attract more viewers to view and share

Constant reference parameter passing ensures parameter immutability within a function and has the following advantages: Parameter immutability: A function cannot modify constant reference parameters. Improved efficiency: no need to create copies of parameters. Error detection: Attempting to modify a constant reference parameter triggers a compile-time error.
