can foreign key take role of primary key?

Answer Posted / gaurav

Yes. This situation occurs in one-to-one relationships.

For example:

create table Table1
( T1_Id integer not null primary key
, T1_Data varchar(9) not null
)
create table Table2
( T2_Id integer not null primary key
, T2_Data varchar(37) not null
, foreign key (T2_Id) references Table1 (T1_Id)
)

Why would someone design two tables like this? If it's a
one-to-one relationship, couldn't you just include T2_Data
in Table1? Yes, you could, although then you would also need
to allow T2_Data to be NULL, if not every T1_Id has a
matching T2_Id—in this case it's actually a
one-to-zero-or-one relationship.

If it's a true one-to-one relationship, where every T1_Id
has a matching T2_Id, then you could combine them without
NULLs. Then the only reason why you might want separate
tables would be if T2_Data were (a) infrequently queried,
and (b) so large that it would result in many fewer physical
rows on a physical database page, which would imply poorer
performance for queries that used only T1_Data.

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between rownum and rowid?

503


Suppose i have a table that contains 5 columns like col1,col2...colm5.I want to import only two column through BCP utility.How to do same through BCP in sybase.

1959


How fixed length strings are truncated and padded?

544


What are subqueries in sql server? Explain its properties.

536


Can a table be created inside a trigger?

559






What is the native system stored procedure to execute a command against all databases?

534


What are locks in sql?

533


what is the difference in login security modes between v6.5 and 7.0? : Sql server database administration

643


How can I create a report based on a query? : sql server management studio

556


How secure is sql server database?

521


Tell me what do we need queues in sql service broker?

513


Define union, union all, minus, intersect?

561


Do you know what are various aggregate functions that are available?

523


Mention the differences between local and global temporary tables.

560


How except clause is differs from not in clause?

534