简体   繁体   中英

Adding a foreign key constraint

Is it possible to add a constraint just like foreign key after inserting some values in the table?

If it's possible how can I do it, because I'm trying to add it with

alter table ...add constraint ..foreign key .." 

But I get an error:

impossible de valider (SYS.COMPAGNIEID1) - clés parents introuvables.

In order to have a define a foreign key, you have to have defined a primary key in the "parent" table. For example, using the standard EMP and DEPT tables, you would first define the column DEPTNO as a primary key in the DEPT table. You would then define DEPTNO in EMP table as a foreign key, that references DEPTNO in DEPT. If you have data in you table, (by default) the data will be validated to make sure the data conforms to the constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM