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.

Similar Messages

  • Primary Key and Foreign Key Constraints

    Hi All,
    I would like to know PRIMARY KEY and FOREIGN KEY constraints on existing oracle tables. Could any one suggest me how to find out.
    Thanks,
    RED

    You can query DBA_CONSTRAINTS to get a list of all the constraints on table A and/or table B. The documentation I linked to gives a full list of the data you can see in DBA_CONSTRAINTS, but it includes things like the referenced table name and referenced constraint name for a foreign key constraint. If A is a parent of B or B is a parent of A, you could match up the parent's primary key constraint to the child's foreign key constraint.
    More generally, though, if you don't know that one of the tables is a parent of the other, figuring out how to join the two tables is probably not something that can be done using just the Oracle data dictionary. You would probably need an understanding of the data model being used to figure out what intermediate table(s) needed to be joined in order to relate rows in A to rows in B.
    Justin

  • Short key for copy does not work all the time now.

    After I have installed the latest OSX - Yosemite, my short key for copy does not work all the time.  It is infrequent how it works. I'm using the same keyboard that I have always used, my wireless logitech keyboard for mac.  Please help.

    I've plugged in my default mac keyboard and the short key copy still does not work.

  • Few keys in Keyboard is not working.

    Few days back my laptop( HP Pavilion G6) screen got froze(Laptop starting but no display, caps key blinking 3 times) so i checked on internet and come to know its may be because of error in memory module. So i put my RAM in other slot. Now my laptop started but a new issue occured.
    Now my caps, B,N ,Del keys in keyboard is not working. I am using Windows 7(64 bit)
    Please help me with this issue.

    Hi
    Please find the steps given below might help you to fix your issue.
    Go to device manager & uninstall the keyboard driver and restart the unit.
    Please update the driver for Bios.
    Try doing a system restore to the date where unit was working fine.
    Open command prompt type the letter and check if does not work you might have to replace the keyboard itself.
    Let us know how it goes!
    "I work for HP."
    ****Click the (purple thumbs up icon in the lower right corner of a post) to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    Regards
    Manjunath

  • How to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.

    how to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.  thanks

    INSERT targetdb.dbo.tbl (col1, col2, col3, ...)
       SELECT col1, col2, col3, ...
       FROM   sourcedb.dbo.tbl
    Or what is your question really about? Since you talke about foreign keys etc, I suspect that you want to transfer the entire table definition, but you cannot do that with an INSERT statement.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • HT1349 how can i open the ipad , the slide key on the screen not working.?

    how can i open the ipad , the slide key on the sreen not working ?

    Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430

  • The "alt, ctrl and shift" on the left side of my keyboard keys integrated notebook did not work. What should I do?

    The "alt, ctrl and shift" on the left side of my keyboard keys integrated notebook did not work. What should I do?

    Hi Luis Fernando Garcia,
    Thanks for using Apple Support Communities.  This article has troubleshooting for keys not working on your keyboard:
    One or more keys on the keyboard do not respond
    http://support.apple.com/kb/ts1381
    Some keys don't work as expected
    From the Apple menu, choose System Preferences.
    From the View menu, choose Speech.
    Click the Text to Speech tab.
    If "Speak selected text when the key is pressed" is enabled, the key or key combination set to speak text cannot be used for other purposes or used to type text--click Set Key and change it to a less-commonly used key combination (try to use modifier keys such as Shift, Command, Option, and Control). Or, disable the "Speak selected text when the key is pressed" option.
    Click the Universal Access pane in System Preferences, click the Keyboard tab.
    Make sure that Slow Keys is turned off. With Slow Keys on, you need to press a key for a longer period of time for it to be recognized.
    In the Universal Access pane, click the Mouse tab, and make sureMouse Keys is turned off. With Mouse Keys enabled, you cannot use the Numeric Keypad to enter numbers--instead the keypad moves the pointer (cursor). (There is an option to enable Mouse Keys with five presses of the Option key; you may want to turn that option off to avoid accidentally enabling it.) If Mouse Keys is enabled and you are using a keyboard with no numeric keypad or Num Lock function, seeUnable to type while Mouse Keys is enabled in Mac OS X.
    If the function keys on the top row of the keyboard are not working as expected, see Mac OS X: How to change the behavior of function keys.
    If the issue persists, use Keyboard Viewer to help isolate the issue:
    Click the Language & Text pane (Mac OS X v10.6) or International pane (Mac OS X v10.5.8 or earlier) in System Preferences.
    Click the Input Sources tab (or Input Menu tab in Mac OS X 10.5.8 or earlier).
    Click the Keyboard & Character Viewer "On" checkbox to select it (click the Keyboard Viewer "On" checkbox in Mac OS X 10.5.8 or earlier).
    From the Input (flag) menu, choose Show Keyboard Viewer.
    If the keyboard is connected and detected by Mac OS X, the keys you type will highlight in the Keyboard Viewer window. Open TextEdit (or any text application), and try to type something using the keys that were previously not responding to see if they highlight in Keyboard Viewer.
    Cheers,
    - Ari

  • Body damage and left and right keys of keyboard is not working

    Body damage and left and right keys of keyboard is not working...from where it fix it is possible to change the body and keyboard how much it cost?

    Hello @harmankakkar ,
    Welcome to the HP Forums!
    I understand your notebook has taken on some damage to the chassis and keyboard.
    You can find a full list of parts for the product, and the steps to replace them yourself in the Maintenance and Service guide available in the User Guide section on your products support page here: HP - Drivers & Downloads.
    You will need your exact product or model number to access this information. For information on finding your product and model numbers click here: How Do I Find My Model Number or Product Number?
    Using the part numbers will allow you to search both the HP Part Store and third party vendors (like eBay and Amazon) for the cheapest parts. 
    You may also want to consider contacting HP Phone Support as they can give you an exact quote on costs for repair to your notebook. You can contact HP Technical Support at 1-800-474-6836 in North America. For all other regions click here.
    Hopefully this information helps!
    Please click the "Kudos, Thumbs Up" at the bottom of this post if you want to say "Thanks" for helping!
    Please click "Accept as Solution" if you feel my post solved your issue, it will help others find the solution.
    The Great Deku Tree
    I work on behalf of HP.

  • Hi, i have a problem that my macBook pro keys suddenly stopped working. The power button,volume keys, brightness keys and shortcuts do not work. Does anyone know why or how i can fix this problem?

    hi, i have a problem that my macBook pro keys suddenly stopped working. The power button,volume keys, brightness keys and shortcuts do not work. Does anyone know why or how i can fix this problem?

    hi, i have a problem that my macBook pro keys suddenly stopped working. The power button,volume keys, brightness keys and shortcuts do not work. Does anyone know why or how i can fix this problem?

  • When I press "****" and r key capitol r dose not work.

    When I press "****" and r key capitol r dose not work. I restarted my computer, and it did not solw the problem. I tried a wired keyboard and it dose the same.

    Hi, thanks for tying to solw my problem. I found that I have set up 3 defferent keys to start defferent programs. I have assigned capitol "c" for start a gmail massege, "r" dose not do anything, and shift plus "g" also  starts the gmail to creat masege.
    I just do not remember where I did it in sys window I tried all the icons and no luck.
    If you would know where to find the coresponding program to change it back please let me know.
    Thanks

  • Mapping in OWB with primary key and foreign key relationship

    Hi all,
    I am new to this datawarehousing field. I have just started my career. I have to now create a mapping in owb where a table has a field which is a primary key of another table in the same staging area. If you guys could help me out with the a method it can be created that would be very helpful to me.
    I thought of 2 ideas,
    1. If I can use a look up, but then I am not sure if i can use a lookup for primary key, foreign key relationship. If I can use also, I do not know how to use that.
    2. What if I can directly take that the first table and link the primary key of that table to the second table which uses that primary key of the first table as one of its fields.
    I do not know how feasible these methods are. Please guys help me out.
    Thanks in advance.

    I have a similar case where table a and table b having relation but table a got inserted with data and table b is empty so there no values for foriegn key column in table b to realte with table a.
    Now i want to load table b foriegn key with primary key column values of table a.
    how can we do this in owb
    thanks
    kumar

  • Primary key and Foreign Key

    Hello,
             I have a question which was asked in an interview
    Can a Primary key in a table also act as a foreign key in the same table ?
    If yes than please provide a simple example
    Thanks
    www.techgulf.blogspot.com

    See this illustration
    create table t
    id int identity(1,1) not null primary key,
    val varchar(100)
    create table t2
    id int not null primary key,
    val varchar(100)
    -- make pk itself as fk to table t
    alter table t2 add constraint fk_t2 foreign key (id) references t(id)
    --some test values to t
    insert t (val)
    values ('test'),('test1'),('test2')
    -- populate t2 first two suceeds
    insert t2(id,val)
    values (1,'iuyi')
    insert t2(id,val)
    values (2,'ef24r')
    -- this will fail as we dont have record with id 4 in t
    insert t2(id,val)
    values (4,'weqw')
    --check the output
    select * from t
    select * from t2
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Primary Key from foreign keys

    I have a table which has 3 foreign keys, two of which form the primary key.
    I have: ID_Product, ID_Sale, ID_Buy, and also an attribute which tells if its a buy or a sale.
    So, if a sale is made, the primary key should consist of ID_Product && ID_Sale, otherwise, it's ID_Product && ID_Buy.
    Is there a way to do this in Oracle, and if there is, can you point me to where I can read about this?
    thank you in advance

    tashe,
    This is the wrong forum for you question. Try posting here:
    PL/SQL
    I will say, however, that there are advantages to keeping your primary keys apart from your data - just populating them from a sequence. Also, you may be temped to enforce this via triggers, but read the following first:
    http://tkyte.blogspot.com/2008/05/another-of-day.html
    Not that you would have a mutating table problem, but the two table solution may help you. Really think the design through.
    Regards,
    Dan

  • Control key (^) combined shortcuts does not work on mac book pro

    All shortcut combinations with the control key (^) do not work. I´m using Mac Book Pro 13 (late 2013) with Os X Mavericks 10.9.4

    The Logic Board is the Main system board. In the Windows world better known as the Motherboard. Except with Apple Mac computers the CPU and the GPU are Soldered to the logic board and if it is a Retina screen model the RAM is also Soldered to it.
    So replacing the Logic board is like replacing the compete system and costs accordingly.
    But there isn't much else you can do if you can't get that switch unstuck. Or just go without sound from the built in speakers. They aren't that good anyway.

  • How to create a primary key or foreign key

    in the table student, sid should be the primary key
    in the table prerequisite cnum should be the foreign key and prereq the primary key
    please help me with the syntax thanks.

    As I said in your other post, it's all in the docs, go first to http://tahiti.oracle.com and try to find the answer yourself
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/clauses3a.htm#1002630

Maybe you are looking for