Home > database >  Outside the SQL key decisions key why still can't insert duplicate data when inserting data?
Outside the SQL key decisions key why still can't insert duplicate data when inserting data?

Time:11-02

This is to create table code:
 CREATE TABLE coordinating editor responsible for and the author 
(
EDIT_UID varchar (13) PRIMARY KEY,
AUTHOR_UID varchar (13) NOT NULL,
Foreign key (EDIT_UID) references to edit information table (EDIT_UID),
Foreign key (AUTHOR_UID) references the author information table (AUTHOR_UID),
);


This is the insert statement:
 INSERT INTO coordinating editor responsible for and the author 
VALUES (' 0001 ', '0001'),
(' 0002 ', '0002'),
(' 0003 ', '0003'),
(' 0004 ', '0004'),
(' 0005 ', '0005'),
(' 0006 ', '0006'),
(' 0007 ', '0007'),
(' 0009 ', '0008'),
(' 0009 ', '0009'),
(' 0010 ', '0010'),
(' 0011 ', '0011'),
(' 0011 ', '0012'),
(' 0013 ', '0013'),
(' 0014 ', '0014'),
(' 0015 ', '0015'),
(' 0016 ', '0016'),
(' 0017 ', '0017'),
(' 0018 ', '0018'),
(' 0019 ', '0019'),
(' 0020 ', '0020');

Primary key have repeated will prompt can't insert duplicate keys, my feeling is when I create table statement has a problem, but I was a little white, don't know how to change, seek answers the duck!!!!!

CodePudding user response:

First of all, the primary key is definitely not allowed to repeat, even is the foreign key family key,

Since you take foreign key family key, why not just take edit information table to save the data in this table?

CodePudding user response:

Table, the primary key is the only...
It is best to learn (book or baidu), foreign key Settings,

CodePudding user response:

reference 1st floor RINK_1 response:
first of all, the primary key is definitely not allowed to repeat, even is the foreign key family key,

Since you take foreign key family key, why not just take edit information table to save the data in this table,

But I searched a foreign key family bond, the primary key can be repeated, and an editor to manage multiple authors that also can only introduce the author UID as foreign keys to edit list

CodePudding user response:

refer to the second floor hgwyl response:
table inside, the primary key is the only...
It is best to learn (book or baidu), foreign key Settings,

But baidu is foreign key family bond, the primary key can be repeated

CodePudding user response:

reference 4 floor weixin_45755568 response:
Quote: refer to the second floor hgwyl response:
table inside, the primary key is the only...
It is best to learn (book or baidu), foreign key Settings,

Foreign key family bond, but baidu is the primary key can be repeated!


Big brother you "see" or "read" carefully enough...
The primary key is the most important table inside, the only sign, the so-called "primary key can be repeated," where is definitely see a bifurcation ~
If the "primary key can be repeated", this is can: joint primary keys,
Such as the primary key is a "class + student id", alone to see a "class", that there is a repeat, but "class + student id" absolutely not repeat,

CodePudding user response:

I feel we technology about, so much word,
In a child table, is your "coordinating editor responsible for and the author"
1, the primary key, ID, since the increasing (do not give any other meaning),
2, coordinating editor responsible for, to the field; Author, to a field, the query or modify do the connection is good,
- if there is need to modify later, you have to make a whole this key the key to the problem, direct look at the SQL statement is easier,
- anyway I couldn't do the "one pace reachs the designated position" of the system, so how simple how to,

CodePudding user response:

outside the SQL key decisions key why still can't insert duplicate data when inserting data?


Primary key and UNIQUE cannot repeat, this is for sure, has nothing to do with the data source table, with the primary key column refer to the who, it does not matter,
  • Related