Create
Procedure
Genforeignkey
@ Tablename
Varchar
(
200
)
--
Name of the table in the foreign key database to be added
As
Declare
@ Cur
Cursor
Declare
@ FK
Varchar
(
100
)
Declare
@ Execsql
Varchar
(
8000
)
Begin
Declare
@
is not necessarily a primary key, but must be a unique index.
primary KEY constraints and uniqueness constraints are unique indexes.
FOREIGN KEY Constraint
SQL Server 2008Other versions
A foreign
, select Yes in the pop-up window, and then add three tables, then you can see the relationship between the three tables.3.2 Setting foreign keys with SQL statements3.2.1 Select Database->sqltest, and then select New Query. Notice the box in the upper left corner to select Sqltest, if not, select it manually.3.2.2 Enter the following code in the new query interface:--This is the comment information in
determines the record of another table, which is used to maintain data consistency. For example, a field in a table is the primary key of table B, so he can be a foreign key to table A
(SQL The data distribution and subscription mechanism of the server allows us to replicate the data between libraries, and the autogrow field may cause a primary key conflict when the data is merged. Imagine that the order table in one database replicates the number of order tables in another library According to the library, OrderID should not automatically gro
.
In addition, when we need to replicate data between multiple databases (SQL Server's data distribution, subscription mechanism allows us to replicate data between libraries), auto-growing fields can cause primary key conflicts when data is merged. When you imagine that an order table in a database replicates a database to an OrderID in another library, should
specific principle here is not clear, the above is only speculation, hereby recordedIf you find a reason to update!Update:Https://stackoverflow.com/questions/22013511/mysql-error-1215-hy000-cannot-add-foreign-key-constraintThat is to say, my above guess is correct!Take a look at the unique test:Transferred from: http://www.cnblogs.com/Andy963/p/7634537.htmlThe last thing to note is that the
Tags: style blog ar color sp for on data divThe role of the primary and foreign keys of sql:Foreign key value rule: A null value or a reference primary key value.(1) When a non-null value is inserted, it cannot be inserted if the value is not in the primary key table.(2) Whe
TABLE Teacher ( te_id int PRIMARY key auto_increment,--primary key self-increment, non-null unique Te_name varchar () NOT NULL,--non-null Te_subject varchar () NOT NULL,--non-null Te_yn varchar Check (te_yn= ' y ' or te_yn= ' n ')--limit only to ' Y ' or ' n ' ) Teacher Class Association table (Cla_teacher) CT_ID (ass
Simple tutorial on SQL statements in linux --- primary key, foreign key, and SQL
Primary Key)Each item in is a unique value in the table. In other words, it is used to uniquely identify
withno_logDBCCshrinkdatabase (database name)execsp_dboption \'database name \', \'autoshrink\', \'true\'
\\\'Add field General function Sub AddColumn (tablename,columnname,columntype) Conn.execute (\ "Alter Table \" tablename\ "add \" columnname\ "\" columntype\ "\") End Sub \\\'Change the field general function Sub Modcolumn (tablename,columnname,columntype) Conn.Execute(\"Alter Table\"TableName\"Alter C
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.