foreign key as a primary key

hi,

I am using a foreign key (which is a primary key in a secondary table)
as a primary key in a primary table.
There is also another primary key in the primary table.
Do You have to declare the foregin key as a primary key  ?
regards
Jan Eikeland
email:jaeikela@c2i.net
url  :http://home.c2i.net/jaeikela
0
jaeikela
12/30/1998 10:41:12 AM
sybase.sqlanywhere.general 32637 articles. 4 followers. Follow

2 Replies
740 Views

Similar Articles

[PageSpeed] 51

In article <368b0234.5056065@forums.powersoft.com>, jaeikela@c2i.net 
says...
> hi,
> 
> I am using a foreign key (which is a primary key in a secondary table)
> as a primary key in a primary table.
> There is also another primary key in the primary table.
> Do You have to declare the foregin key as a primary key  ?
> regards
> Jan Eikeland
> email:jaeikela@c2i.net
> url  :http://home.c2i.net/jaeikela
> 

Can you post the DDL that you are using?  What you are asking probably 
isn't a problem but I want to be sure.
-- 
Jim Egan [TeamPS]
Dynamic Data Solutions, Inc. http://www.dyn-data.com
Houston, TX
0
jegan
12/30/1998 2:22:37 PM
jaeikela@c2i.net (Jan Eikeland) wrote:

>hi,
>
>I am using a foreign key (which is a primary key in a secondary table)
>as a primary key in a primary table.
>There is also another primary key in the primary table.
>Do You have to declare the foregin key as a primary key  ?
>regards
>Jan Eikeland
>email:jaeikela@c2i.net
>url  :http://home.c2i.net/jaeikela

Ow, my head hurts! (and perhaps yours does too :)

Generally if the CREATE TABLE and ALTER TABLE commands work, you can
do it (create various primary and foreign keys). Maybe that doesn't
answer your question, but then you're gonna have to be more specific.

The term "primary key" applies to the set of one or more columns that
are defined as the primary key (yeah, that's a circular definition).

The term "primary key column" refers to one of the columns in a
primary key. Therefore, there can be more than one primary key column
but only one primary key, per table.

The same difference applies to "foreign key" versus "foreign key
column". Except that one table can contain a zillion foreign keys (and
often do, especially in banks and government departments :)

Rule: Each foreign key in table A must point at the primary key in
some other table B... column for column, an exact match.

Foreign key columns in table A can be included in the primary key for
table A but they don't have to be. They DO have to point at the
primary key in table B.

To make things interesting: loops are possible. I.e., table A and
table B can be the same table. Or different tables, with A pointing at
B *and* vice versa. With a loop at least one of the foreign keys must
be NULLable or it would be impossible to do an INSERT (but what about
WAIT_FOR_COMMIT? hmmmm...:)

Anyway, I'm sure your head hurts as much as mine now <g>. If this
didn't help, just restate your question in precise terms... maybe
include the CREATE/ALTER TABLE commands you want to use.

Breck

0
bcarter
12/30/1998 2:24:45 PM
Reply:

Similar Artilces:

integer primary/foreign key vs. varchar(255) primary/foreign key
Hello. Is there any principal performance (or some other) difference between using the integer primary/foreign key and using the string (varchar(255)) keys in queries that use tables joins? Server is Sybase SQL Anywhere 5.5.04 Yes! The primary key will only be made up of 12 bytes. By using an integer you ensure that your entire column is in the key. -- Jim Egan [TeamPS] Dynamic Data Solutions, Inc. http://www.dyn-data.com Houston, TX *********************************************************** Enterprise Applications in Your F...

Primary key/Foreign key again
Thanks, Nat and David. Under "SQL Anywhere", I get into ISQL to use "ALTER TABLE" command to add my primary key: ALTER TABLE Client ADD PRIMARY KEY (SYSID) I got an error: user 'dba' has the row in 'Client' locked. How can I release the locking condition? Click on another table in Sybase Central. Is suspect this is the issue. Dave Wolf Jaguar Product Team John Chyan wrote: > Thanks, Nat and David. > > Under "SQL Anywhere", I get into ISQL to use "ALTER TABLE" command > to add my primary key: > ...

Primary Key/Foreign Key
Can I use SQL Commands to add Primary key or reference keys to existed tables? (Not a new table, that's why I can't use CREATE TABLE command.) If does, could someone give me some sample codes? Thanks. Hi John, What you need is the ALTER TABLE statement. Look for it in SQLA help for the syntax. Regards, Nat. John Chyan wrote in message <35A4FF5D.5F192806@dissol.com>... >Can I use SQL Commands to add Primary key or reference keys to existed >tables? (Not a new table, that's why I can't use CREATE TABLE command.) > >If does, could someone ...

Primary key
Hello, I've got a modeling problem betwin a conceptual model and a physical model and espacially about the foreign key. See below the illustrated exemple of the problem : -Whether the entity � ARTICLE � with two informations : CODE & WORDING -Whether the entity � UNITE � with two informations : CODE & WORDING An article has necesseraly three unity, the unity of command, of storage and of sails. These three unity can be differents. Conceptual model phycical model The generated physical model doesn't suitable me. How ...

primary key and foreign Key????
 Hi i have 2 table.. Table1UID         Username1               AB2               CD3               DD Table 2ITEM       Price          UIDPOO1      20.00          1POO2      10.00          2POO3       15.00         1 Now i am letting the Admin to delete the user in table1But since UID 1 and 2 are ...

Keys, keys,keys...
Just installed PGP 6.5.8 and all is running fine, so far :-) Question: When I opened the PGP Keys window for the first time, apart from the *Create Key* wizard, there are about 50 odd keys belonging to various and sundry at NAI. Were these supplied for a purpose or only for illustration? Is there any reason they could not or should no be deleted? Question 2: I sent someone an encrypted test message using that person's public key. It went off fine except, I am left with only the encrypted eMail. What setting should I change in order for my eMail client (Outlook 2000) ...

Primary key
> Je me permet de soliciter une aide sur poweramc V8. > Je suis en charge d'un projet ERP et je me pose la question suivante sur un > exemple de mod�lisation. > > Entit� : ARTICLE > information : Code article > Information : Libell� article > > Entit� : Unit� > Information : Code unit� (exemple : Kg, palette, m2...) > information : Libell� unit� > > Un article a 3 unit�s, unit� de stockage, unit� de vente et unit� d'achat. > Ces trois unit�s peuvent �tre diff�rentes. > > Dans mon MCD, j'...

composite primary key and foreign key
I refer a composite primary key of a master table, I have to refer all the fields of the composite primary key. But how to partially refer the composite primary key in a child table? For example, if PARENT table  has primary key (A,B,C), how to create a foreign key in CHILD table which will refer only (A,B) fields of Table1?  Hi, Please refer to the following description: MSDN: In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table...

Foreign keys have the same columns as primary key
After upgrading from AppModeler 6.0 to 6.1 when I check my PDM I'm getting the following warning messages on a lot of columns: Foreign Keys have the same columns as primary key. The suggested correction doesn't help much. Can some one explain this warning to me? It seems that when the primary key of one table is a foreign key from another table this warning is poping up. Any help appreciated. Thanks, -- James L. Knowlton President and Programer/Analyst Law Enforcement Automated Data Systems, Inc Richmond, VA begin 666 James L. Knowlton.vcf M0D5'24XZ5D-!4D0-&q...

No primary key value for foreign key
Hi, I tried to: alter table sa.shipitems add foreign key FK_SHIPITEM_REFERENCE_OITEMS (oitemsid) references sa.oitems (oitemsid) on update cascade on delete restrict but got this error: No primary key value for foreign key 'FK_SHIPITEM_REFERENCE_OITEMS' in table 'shipitems' What does it mean and how to round this problem? fyi, here is the definition of both table /*==============================================================*/ /* Table: shipitems */ /*===============================...

Primary Key/Foreign Key relationship errors
Hey All,  So I am having trouble getting Dynamic Data to set up my SQL Data properly. For some reason, it is not reading the primary key/foreign key relationships correctly. Here is an example of the warning message I am getting:  Warning 1 DBML1062: The Type attribute 'UpdatedInfo' of the Association element 'Location_UpdatedInfo' of the Type element 'Location' does not have a primary key.  No code will be generated for the association.  0 0 Warning 2 DBML1062: The Type attribute 'UpdatedInfo' of the As...

Foreign key constraint to a composite primary key
I have two tables: table 1 and table 2. The primary key of table is composite key of two collumns and table 2 is the child of parent table 1. Is it possible to create / define a foreign key constraint using a composite primary key? Yes u can give foreign key constraint to the table 2 but the composite primary should be there in foreign table. For eg. table 1 has 2 columns (e-id, e-name) as composite primary key then table2 must have (e-id,e-name) as the columns (maybe with different headings) but the foreign key can be set.Sagar Virani The syntax for a referential constraint is: &nb...

Foreign key duplicates part of primary key
I have the following entities with the following identifiers Employee ID Employment - dependent of Employee and Payroll, Many to one relationship to Termination. HIRE DATE Payroll Paycode Termination - dependent of Payroll Term_Code When I generate the physical model I get the following tables and primary keys, foreign keys Employee ID Employment Primary Key Pay_Code ID HireDate Foreign Key Term_Code Ter_Pay_Code Payroll Paycode Termination - dependent of Payroll Pa...

Clustered Primary Key and Foreign Key: T-SQL
I am having a little trouble getting this to work right, but have come a ways since I started this.......other tables created first and with no problems..... then these two with the last table being the problemI need to set one foreign key in the second table referencing the first table.But, the primary key is clustered with the two foreign keys and I get the error....There are no primary or candidate keys in the referenced table 'courseScores' that match the referencing column list in the foreign key 'FK_course'.CREATE TABLE dbo.courseScores   (     course...

Web resources about - foreign key as a primary key - sybase.sqlanywhere.general

Foreign Intelligence Surveillance Act of 1978 Amendments Act of 2008 - Wikipedia, the free encyclopedia ...
The FISA Amendments Act of 2008 (also called the Foreign Intelligence Surveillance Act of 1978 Amendments Act of 2008 , H.R. 6304 , enacted 2008-07-10) ...

Western Sydney raids: alleged terrorist cell had Islamic flag, photos of foreign fighters
The arrests of Mohamed Rashad Almaouie, 20, and Abdullah Salihy, 24, brought to seven the number of men allegedly planning to attack police buildings ...

US foreign arms deals up by nearly $13 billion
The US controls just over 50 per cent of the world's weapons markets. Washington: Foreign arms sales by the United States jumped by almost $US10 ...

RYAN AND RUBIO: American Companies Will Go Bankrupt If We Don’t Import More Foreign Workers!
... host Bill Bennett, Rep. Paul Ryan (R-WI) defended his omnibus bill’s controversial expansion in the H-2B visa program, which would allow foreign ...

Liveblogging the Cold War: December 27, 1945: Communique from the Interim Meeting of Foreign Ministersin ...
**Communique**: [Interim Meeting of Foreign Ministers, Moscow](http://avalon.law.yale.edu/20th_century/decade19.asp): >(a) Soviet-Anglo-American ...

Paul Ryan’s Christmas Warning: American Companies Will Shut Down Without More Foreign Workers
Paul Ryan defended his omnibus bill's expansion in the H-2B visa program by arguing that, without it, American companies would shut down.

What will biggest foreign policy challenges be for U.S. next year?
CBS News Senior National Security Analyst Juan Zarate discusses concerns ranging from ISIS to Bashar al-Assad and the type of terrorist threats ...

SAG Benefit Plans Accused Of Being A “Body Shop” For Illegal Foreign Workers
... of firing an older female employee who was undergoing treatment for breast cancer and, to save money, replacing her with a younger, male foreign ...

Buy Rosetta Stone, Farina Tells Parents Upset Over Foreign Language Cuts
... schools chief said parents should buy the language teaching material for their kids. FORT GEORGE — Parents worried about cuts to school foreign-language ...

Foreign Ministers of South Korea, Japan to discuss issue of wartime Korean sex slaves
The foreign ministers of South Korea and Japan will Monday to try to resolve the decades-long thorny issue of Korean women forced into Japanese ...

Resources last updated: 12/28/2015 4:42:08 PM