How to add Foreign key in a table after the creation of the
table?

Answers were Sorted based on User's Feedback



How to add Foreign key in a table after the creation of the table?..

Answer / sagar98

ALTER TABLE <table_name>
ADD CONSTRAINT <fk_name> FOREIGN KEY (column_name)
REFERENCES <table_name_where_this_column_acts_as_PK>
(Column_name)

Is This Answer Correct ?    19 Yes 0 No

How to add Foreign key in a table after the creation of the table?..

Answer / purushotham

we can add a foreign key to a table
1)while creation of table
2)After the creation of the table

by using
Alter table table_name add foreign key(column_name)
References column_name from table_name(that consists of
primary key)

Is This Answer Correct ?    7 Yes 4 No

How to add Foreign key in a table after the creation of the table?..

Answer / devi

alter table table2
add(constraint table2_col2_fk foreign key(col2) references
table1(col1);
here col2 is the foreign key of table2 which refer to the
col1 of table1 which is h epimary key of table1

Is This Answer Correct ?    3 Yes 0 No

How to add Foreign key in a table after the creation of the table?..

Answer / subbu

You cannot add foreign key after creation of the table until
unless you have assigned the primary key while creating the
table. I mean without a primary key assigned for a table, we
cannot add foreign key.

Once the primary key is found, then query to add is been
already given by the above posters.

Is This Answer Correct ?    2 Yes 2 No

How to add Foreign key in a table after the creation of the table?..

Answer / venkatesh

u have create two tables an the time one in first table must an should using primary key .in way of using ddl cmd.
A)alter table table name add fk(clm name) reference column name from table name consists of primary key

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

What is the clause we need to add in function body to return variable?

0 Answers  


if table named a is there and 4 records are there then how to swap (1 and 3) and (2 and 4) records at a time

1 Answers  


Is trigger a stored procedure?

0 Answers  


Is sql pronounced sequel or sql?

0 Answers  


Is left join same as inner join?

0 Answers  






What are the basic sql commands?

0 Answers  


how to select alphabets in a one column , for this the table name is PA_TASKS and column name is TASK_NUMBER, In TASK_NUMBER the data like this 1.1.3NN,1.1.4NN,1.5.1NN,1.3.2NE,1.5NN,1NN,1.2NE,1CE , For this i need to disply output as NN,NN,NN,NE,NN,NN,NE,CE, Its some urgent requirement ,thanks in advance

6 Answers  


What normalization means?

0 Answers  


How do I save a stored procedure?

0 Answers  


What is record variable?

0 Answers  


what command is used to create a table by copying the structure of another table including constraints ?

6 Answers   CMC, eicc,


What is integrity constraints?

5 Answers   Ramco, Satyam,


Categories