Composite foreign key issue

Hi,
I am trying to create a composite foriegn key. I have created my primary key as a composite key, made up of three fields.
Table 1
PatientID - Made from 3 fields(a,b,c)(primry key)
Table B
PatiendID- (should be the foreign key which references table1)
However i am finding that when i try to create my constraint i get the following messages
error 02270 - no matching unique or primarty key for this column list.
below is the sample code i am using to create my foreign key)
(ALTER TABLE XD_PatientSedation ADD CONSTRAINT fk_Sedation_PatientID FOREIGN KEY (PatientID)REFERENCES XD_Patient_Demographics(PatientID)
I am really stuck on this and dont quite know what to do.
Hope you can help.
Thanks
Jagdish

Just speaking about design, when you want to use a foreign key, it already means that the referenced columns represent something important enough to be a primary key of some other table. I don't understand the business logic of your example (using real table and column names would help), but the solution is probably one of these two :
a) your foreign key should in fact refer to (a,b,c), the complete primary key of the first table (what was suggested by the others).
b) your foreign key should stay as 'a' (patientid?), you should have a third table (patients?) whose primary key is 'a', and your "Table 1" should have a foreign key on 'a', referencing the third table. In this case you may find it silly to create a new table with only one column, but I would bet that you will very soon think of interesting attributes which could be added to this table.
In any case, I think that Oracle did a good job by forcing an improvement of your design !

Similar Messages

  • Need help with defining composite foreign keys

    Hi there, i´m in troubles with defining a composite foreign key. The scenario is:
    * Table TABLE_A has no unique primary key. Instead its primary key is a composition of five foreign keys.
    * Table TABLE_B and TABLE_A have a many-to-many relationship with each other.
    When I create the entity manager for running the DDL scripts into the DB i´m getting "ORA-02270: no matching unique or primary key for this column-list".
    These are my entities (sorry the portuguese terms, but i think the issue can be understood without translation...).
    @Entity
    @Table( name = "DESTAQUE_PDE" )
    public class DestaquePDE implements Serializable {
         private static final long serialVersionUID = 4694859522628884981L;
         @Id
         @GeneratedValue( strategy = GenerationType.SEQUENCE )
         @Column( name = "ID_DESTAQUE_PDE", nullable = false )
         private long id;
    //Some fields were ommited here for simplicity....
         @ManyToMany( cascade = CascadeType.ALL )
         @JoinTable( name = "JOIN_DESTAQUES_CORRELACAO",
                        joinColumns           = @JoinColumn( name = "JOIN_ID_DESTAQUE", referencedColumnName = "ID_DESTAQUE_PDE" ),
                        inverseJoinColumns      = {@JoinColumn( name = "JOIN_ID_COR_PUB_ALVO", referencedColumnName = "FK_ID_PUBLICO_ALVO" ),
                                                 @JoinColumn( name = "JOIN_ID_COR_RES_LINHA", referencedColumnName = "FK_ID_RESOLUCAO_LINHA" ),
                                                 @JoinColumn( name = "JOIN_ID_MOD_CRED", referencedColumnName = "FK_ID_MODALIDADE_CREDITO" ),
                                                 @JoinColumn( name = "JOIN_ID_AG_FIN", referencedColumnName = "FK_ID_AGENTE_FINANCEIRO" ),
                                                 @JoinColumn( name = "JOIN_ID_PROG_LINHA", referencedColumnName = "FK_ID_PROGRAMA_LINHA" )}
         private List<EntradaTabelaCorrelacao> correlacoes;
    @Entity
    @Table( name = "CORRELACAO" )
    @IdClass( TabelaCorrelacaoPK.class )
    public class EntradaTabelaCorrelacao implements Serializable {
         private static final long serialVersionUID = -3337072470212918325L;
         @Id
         @Column( name = "FK_ID_PUBLICO_ALVO" )
         private long idPublicoAlvo;
         @Id
         @Column( name = "FK_ID_RESOLUCAO_LINHA" )
         private long idResolucaoLinha;
         @Id
         @Column( name = "FK_ID_MODALIDADE_CREDITO" )
         private long idModalidadeCredito;
         @Id
         @Column( name = "FK_ID_AGENTE_FINANCEIRO" )
         private long idAgenteFinanceiro;
         @Id
         @Column( name = "FK_ID_PROGRAMA_LINHA" )
         private long idProgramaLinha;
         @Column( name = "CS_SITUACAO", nullable = false, length = 1 )
         private String situacao;
         @ManyToMany( mappedBy = "correlacoes" )
         private List<DestaquePDE> destaquesPDE;
    //more relationships ommited for simplicity....
    public class TabelaCorrelacaoPK implements Serializable {
         private long idPublicoAlvo;
         private long idResolucaoLinha;
         private long idModalidadeCredito;
         private long idAgenteFinanceiro;
         private long idProgramaLinha;
    //getters and setters ommited....
    These are part of the DDLs generated by toplink:
    CREATE TABLE DESTAQUE_PDE (
         ID_DESTAQUE_PDE NUMBER(19) NOT NULL,
         VL_ALOCACAO_AUTORIZADA NUMBER(16,2) NOT NULL,
         VL_TOTAL NUMBER(16,2) NOT NULL,
         QT_OPERACOES NUMBER(16,2) NOT NULL,
         NM_DESTAQUE_PDE VARCHAR2(255) NOT NULL,
         VL_ESTIMATIVA_REAPLICACAO NUMBER(16,2) NOT NULL,
         VL_MONTANTE NUMBER(16,2) NOT NULL,
         FK_ID_PDE NUMBER(19) NOT NULL,
         FK_RESOLUCAO_PROGRAMA NUMBER(19) NOT NULL,
         PRIMARY KEY (ID_DESTAQUE_PDE)
    CREATE TABLE CORRELACAO (
         FK_ID_PUBLICO_ALVO NUMBER(19) NOT NULL,
         FK_ID_RESOLUCAO_LINHA NUMBER(19) NOT NULL,
         FK_ID_MODALIDADE_CREDITO NUMBER(19) NOT NULL,
         FK_ID_AGENTE_FINANCEIRO NUMBER(19) NOT NULL,
         FK_ID_PROGRAMA_LINHA NUMBER(19) NOT NULL,
         CS_SITUACAO VARCHAR2(1) NOT NULL,
         PRIMARY KEY (FK_ID_PUBLICO_ALVO, FK_ID_RESOLUCAO_LINHA, FK_ID_MODALIDADE_CREDITO, FK_ID_AGENTE_FINANCEIRO, FK_ID_PROGRAMA_LINHA)
    ALTER TABLE DESTAQUE_PDE
    ADD CONSTRAINT FK_DESTAQUE_PDE_FK_ID_PDE
    FOREIGN KEY (FK_ID_PDE)
    REFERENCES PDE (ID_PDE)
    ALTER TABLE DESTAQUE_PDE
    ADD CONSTRAINT DESTAQUEPDEFKRESOLUCAOPROGRAMA
    FOREIGN KEY (FK_RESOLUCAO_PROGRAMA)
    REFERENCES RESOLUCAO_PROGRAMA (ID_RESOLUCAO_PROGRAMA)
    (*) ALTER TABLE CORRELACAO
    ADD CONSTRAINT CORRELACAO_FK_ID_PUBLICO_ALVO
    FOREIGN KEY (FK_ID_PUBLICO_ALVO)
    REFERENCES PUBLICO_ALVO (ID_PUBLICO_ALVO)
    ALTER TABLE CORRELACAO
    ADD CONSTRAINT CORRELACAOFKID_RESOLUCAO_LINHA
    FOREIGN KEY (FK_ID_RESOLUCAO_LINHA)
    REFERENCES RESOLUCAO_LINHA (ID_RESOLUCAO_LINHA)
    ALTER TABLE CORRELACAO
    ADD CONSTRAINT CRRELACAOFKIDMODALIDADECREDITO
    FOREIGN KEY (FK_ID_MODALIDADE_CREDITO)
    REFERENCES MODALIDADE_CREDITO (ID_MODALIDADE_CREDITO)
    ALTER TABLE CORRELACAO
    ADD CONSTRAINT CORRELACAOFKIDAGENTEFINANCEIRO
    FOREIGN KEY (FK_ID_AGENTE_FINANCEIRO)
    REFERENCES AGENTE_FINANCEIRO (ID_AGENTE_FINANCEIRO)
    ALTER TABLE CORRELACAO
    ADD CONSTRAINT CORRELACAOFK_ID_PROGRAMA_LINHA
    FOREIGN KEY (FK_ID_PROGRAMA_LINHA)
    REFERENCES PROGRAMA_LINHA (ID_PROGRAMA_LINHA)
    As I told before, the error i´m getting with these mappings is:
    ORA-02270: no matching unique or primary key for this column-list
    The error occurs exactly when executing the instruction with (*).
    Thanks in advance for any help!
    Regards
    Loreno

    The error says that the table PUBLICO_ALVO does not have a primary key or unique constraint for (ID_PUBLICO_ALVO), so you cannot define a foreign key constraint to it. This table was not included in your DDL, how was it created? You need to add a primary key or unique constraint in this table on this field.
    If you do not wish to have the unique or foreign key defined you can just ignore the error, it is just a warning.
    <p>---
    <br>James Sutherland
    <br>Oracle TopLink, EclipseLink
    <br>Wiki: Java Persistence, EclipseLink

  • Composite Foreign Keys

    How do I map a composite foreign key using toplink?
    I can reference a particular record in mytable using the following sql statement:
    SELECT * FROM mytable m WHERE m.foreign_id = x AND m.type = y;
    Where x represents the primary key in my entity and y represents a second part of the primary key (e.g. "type 1")
    How do I accomplish this from within my entity?
    Thanks

    If you are using JPA, you need to use either an IdClass or EmbeddedId for composite primary keys.
    If you are using the TopLink native API you just need to call addPrimaryKeyFieldName() with both column names.
    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Composite_Primary_Keys
    James : http://www.eclipselink.org

  • Optional Composite Foreign Key

    The tool doesn't seem to be handling this correctly when some of the columns are mandatory and others are nullable. I have a composite foreign key where one column is part of the primary key and the other is not. In the Columns properties of the Table dialog, it shows the column that is part of the primary key as mandatory. But on the diagram, the "red dot" indicator is missing. It also give me an error on the Foreign Keys properties when I click OK or Apply.

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

  • Composite Foreign Key Relationships

    I'm having problems defining relationships that are using the same set of fields in a composite primary key and a composite foreign key. Are there any examples for doing this kind of thing. I think I have the primary keys set up correctly but the foreign key defs aren't working yet. From the spec it looks ike it should be something like this:
    @ManyToOne
         @PrimaryKeyJoinColumns({
         @PrimaryKeyJoinColumn(name="CGMTI_ID"),
         @PrimaryKeyJoinColumn(name="MISSION_REF_DATE")})
         CgmtiHeader cgmtiHeader;
    Also, the composite foreign keys seem to make Dali's entity generation blow up.

    This mapping is missing the referencedcolumn definition, and because it is a composite pk, it cannot figure out a default value. So it should similar to:
    @ManyToOne
    @PrimaryKeyJoinColumns({
    @PrimaryKeyJoinColumn(name="CGMTI_ID", referencedColumnName="CGMTI_ID),
    @PrimaryKeyJoinColumn(name="MISSION_REF_DATE", referencedColumnName="MISSION_REF_DATE)})
    CgmtiHeader cgmtiHeader;
    Similar discussions exist in threads:
    Extra Columns in ManyToMany table workaround
    and
    http://forums.java.net/jive/thread.jspa?threadID=2564&messageID=36441
    both of which list blogs showing examples.
    Best Regards,
    Chris

  • Composite Foreign Key

    Dear All
    please correct this syntax for composite foreign key.
    Ater Table emp_pays
    Add Constraints emp_pt_fk Foreign Key(emp_id,pt_id) Referenes emp(emp_id),pay_type(pt_id);
    Thanks in advances
    Regards,

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

  • Composite foreign key, LOV, WSG, Designer 6i

    Hello,
    I have one composite foreign key that consists of 3 columns,
    which belongs to three different tables (there are
    master-detal-detail relationships between those 3 tables). Let's
    call those tables A, B and C.
    Now, I'd like to generate wsg module (based on table D) that has
    all three columns displayed. Also, I'd like to generate three
    dependant LOVs in such way that I am able first to select row
    from table A using first LOV. Second LOV should display rows from
    table B, but only those rows that are in context of A. Similary,
    third LOV should display rows from table C, but only rows in
    context of B.
    Is there any way to this in Designer 6i Release 4 ? This way
    default behaviour in Designer 2.1.2 and 6.
    Thanks.
    Goran Oparnica
    IN2 d.o.o.
    Zagreb

    The Headstart Utilities are part of the Headstart Oracle Designer package which is downloadable from OTN. Headstart Oracle Designer is an accelerator suite consisting of Templates, Object Libraries, Preference Sets, PL/SQL libraries and utilities to make using Designer to generate Forms applications easier.
    To get more information on Headstart you can go to the OTN home page, choose Internet Tool under the Products section on the menu. Under the Headstart 'Internet Developer Suite', click on Headstart Oracle Designer
    Regards,
    Lauri

  • Foreign keys issues

    hi guys,
    i m using jdeveloper 11 release 2
    i have created 3 tables one for employee,second for evaluator,third for screening.
    by creating the relationship pk empno(employee) become fk (evaluator) ,then pk evaluatorNo become fk for screening
    i would like when using the LOV ON the screening form to display the employeename and save the evaluatorNo on the database.
    the issue when i select the LOV ON evaluatorNo,on the edit LOV
    I select the list of the data source,on the available object view i select the employeeEO shuttled to the view accessors ( screeningVO)
    back on the edit LOV ,I select empNo under list of attributes.
    then i have view attribute as evaluatorNo
    and list attribute as empNo
    then on the UI Hints i select employeename
    when running the application it shows the employee names on the list box
    but trying to save it says foreign key not found
    any help
    regards
    steve kalenga

    Some trouble-shooting ideas:
    1. Are you using the application model tester or is this on a web page? Try it on the am tester. If that doesn't work, then something is wrong with your model.
    2. How are the primary keys being created? Are you creating first a parent record, then a child record? Is the key for the parent being created? Does the child foreign key populate when you create that record? Have you tried saving the parent record first, then creating the child record?
    3. What method are you using for primary key creation? DBSequence (database trigger) or create method? There are differences in how they are created and that may affect the behavior of the parent/child relationship, or lack thereof.
    Stuart

  • Can not insert null into foreign key issue

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

  • MBAM console not accessible after new installation and self service re-direct to give foreign key issue

    Hello Everyone,
    i am novice to MBAM and i have gone thru the virtual lab and material and i am in process of implementing it for my Organization. i am having 2 issues :-
    1) After installation, i am confused how to access the console or does there is no Admin console and it is just servername:portnumber\helpdesk only.
    2) If i enter just servername:portnumber\ then it get redirected to selfservice portal which is not an issue. Issue is after accepting agreement and clicking continue i am getting below error :-
    A required anti-forgery token was not supplied or was invalid. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not supplied or was invalid.
    Source Error: 
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    Stack Trace: 
    [HttpAntiForgeryException (0x80004005): A required anti-forgery token was not supplied or was invalid.]
       System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext filterContext) +546706
       System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) +128
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +658100
       System.Web.Mvc.Controller.ExecuteCore() +125
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +48
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +15
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +85
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +454
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
    I have checked and usersupportservice.svc is leading to the pade giving below page which i believe it is working OK or kindly correct me if i am thinking wrong :-
    This is a Windows© Communication Foundation service.
    Metadata publishing for this service is currently disabled.
    only thing which i deviated from process was because of some condition i have to rename my MBAM server before installation however by before rename SQL and IIS was installed.
    i will really appreciate any help in this regard.

    If that is the only link or admin console as well then if anyone can confirm what rights difference a user get when he is member of MBAM helpdesk, MBAM Advanced Helpdesk and MBAM Administrator group.
    Also if i can get any help with the self service portal redirection then that will be really helpful. i was also checking if this could be because of any kind of certificate issue as server name was renamed after SQL and IIS installation.

  • Primary key foreign key dependencies

    hi gems...
    I have a table with composite primary key (COL1, COL2)..
    create table TABLE1 (COL1, COL2);
    alter table TABLE1 add constraint PK_TABLE1 primary key (COL1, COL2);
    Now i am trying to make another table which will refer to the COL1 of the first table.
    create table TABLE2 (COL3, COL4);
    alter table TABLE2 add constarint FK_TABLE2 (COL3) references TABLE1(COL1);
    but it is failing with "no matching unique or primary key" error.

    You have created a composite primary key, so there must be composite foreign key that references the composite primary key. You cannot create Foreign key that references to single column of the composite primary key.

  • Does a foreign key have to be a primary key

    Hey all.I was checking on the database code written by sambapos.To my surprise, I found a foreign key that is not a primary key anywhere.
    Is that possible?
    If, so why?
    I am really astonished.

    Limitations and Restrictions
    A foreign key constraint does not have to be linked only to a primary key constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.
    When a value other than NULL is entered into the column of a FOREIGN KEY constraint, the value must exist in the referenced column; otherwise, a foreign key violation error message is returned. To make sure that all values of a composite foreign key constraint
    are verified, specify NOT NULL on all the participating columns.
    FOREIGN KEY constraints can reference only tables within the same database on the same server. Cross-database referential integrity must be implemented through triggers. For more information, see
    CREATE TRIGGER (Transact-SQL).
    FOREIGN KEY constraints can reference another column in the same table. This is referred to as a self-reference.
    A FOREIGN KEY constraint specified at the column level can list only one reference column. This column must have the same data type as the column on which the constraint is defined.
    A FOREIGN KEY constraint specified at the table level must have the same number of reference columns as the number of columns in the constraint column list. The data type of each reference column must also be the same as the corresponding column in the column
    list.
    The Database Engine does not have a predefined limit on either the number of FOREIGN KEY constraints a table can contain that reference other tables, or the number of FOREIGN KEY constraints that are owned by other tables that reference a specific table.
    Nevertheless, the actual number of FOREIGN KEY constraints that can be used is limited by the hardware configuration and by the design of the database and application. We recommend that a table contain no more than 253 FOREIGN KEY constraints, and that it
    be referenced by no more than 253 FOREIGN KEY constraints.
    FOREIGN KEY constraints are not enforced on temporary tables.
    If a foreign key is defined on a CLR user-defined type column, the implementation of the type must support binary ordering. For more information, see
    CLR User-Defined Types.
    A column of type varchar(max) can participate in a FOREIGN KEY constraint only if the primary key it references is also defined as type
    varchar(max).
    Read this article
    http://msdn.microsoft.com/en-us/library/ms189049.aspx
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

  • Foreign key constraint on multi-column primary key accepts 1 empty column!?

    Hi, we have a reference table with a two-column primary key. In the child table there is a non-mandatory foreign key constraint to this table. So if both child columns are null it's ok too. But now we see that if one of the two child table columns that build up the foreign key is null, the other column can have any (non-existant in the master-tabel) value you like!? That does not make sense.
    Can anyone explain this to me???
    Regards, Paul.

    Paul, I believe that this is in accordance to the ANSI SQL standard requirement for the treatment of nulls in a multi-column FK. In any case Oracle specifically states this is the way FK work From the 10 Concepts manual, Ch 21 Data Integrity, topic Nulls and Foreign Keys:
    The relational model permits the value of foreign keys either to match the referenced primary or unique key value, or be null. If any column of a composite foreign key is null, then the non-null portions of the key do not have to match any corresponding portion of a parent key. <<HTH -- Mark D Powell --

  • Adding a foreign key based on composite key of other table

    Hi All,
    I have two tables one named 'products' (T1) and other 'codes' (T2). The product_code column in T1 needs to reference code_id values where code_type="STREET" from T2. T2 primary key is based on two columns 'code_id' and 'code_type'.
    The issue is t1 table has only one of the column from T2. i.e; product_code (T1) corresponds to code_id (T2) and code_type should always have value "STREET"
    I am not getting how to implement the foreign key constraint on T1 in such scenario. Hope my explanation is clear. Feel free to ask for more clarifications. Please suggest.
    Thanks
    Edited by: user5108636 on 26/09/2011 21:20

    user5108636 wrote:
    Hi All,
    I have two tables one named 'products' (T1) and other 'codes' (T2). The product_code column in T1 needs to reference code_id values where code_type="STREET" from T2. T2 primary key is based on two columns 'code_id' and 'code_type'.
    The issue is t1 table has only one of the column from T2. i.e; product_code (T1) corresponds to code_id (T2) and code_type should always have value "STREET"
    I am not getting how to implement the foreign key constraint on T1 in such scenario. Hope my explanation is clear. Feel free to ask for more clarifications. Please suggest.post CREATE TABLE statement for PRODUCTS & CODES tables

  • Composite primary key as foreign key not working

    i want have two tables
    in one table i make a composite primary key
    and in the other table i refer one of the column of the composite key from the above table as foreign key in this table but this didn't work.
    eg:
    create table temp1
    ( name char2(10),
    ssn# number(10)
    address varchar2(10)
    constraint (cons_1)primary key(name,ssn#) );
    create table temp2
    ( name1 char2(10) references temp1(name),
    add varchar(20));
    this didn't work....can't create temp2 table it's giving error

    The following includes some corrections and some suggestions. Your original code had several problems: missing comma, invalid name, invalid data type, no unique key for the foreign key to reference. The following fixes all of those and adds some meaningful names for the constraints and formats it so that it is easier to read.
    CREATE TABLE temp1
      (name       VARCHAR2 (10),
       ssn#       NUMBER   (10),
       address    VARCHAR2 (10),
       CONSTRAINT temp1_name_ssn#_pk
                  PRIMARY KEY (name, ssn#),
       CONSTRAINT temp1_name_uk
                  UNIQUE (name))
    Table created.
    CREATE TABLE temp2
      (name1      VARCHAR2 (10),
       address    VARCHAR2 (20),
       CONSTRAINT temp2_name1_fk
                  FOREIGN KEY (name1)
                  REFERENCES temp1 (name))
    Table created.

Maybe you are looking for