--Statement
1
CREATE
TABLE
FirstTable
(
in_id
int PRIMARY
KEY,
vc_name
varchar(20)
CONSTRAINT
UN_vc_name
UNIQUE(vc_name)
);
--Statement
2
CREATE
TABLE
SecondTable
(
in_id
int PRIMARY
KEY,
vc_person_name
varchar(10)
REFERENCES
FirstTable(vc_name)
);
Question:
What will be the output of both the SQL queries?
Answer:
The SQL Query will execute successfully but the SQL Query will throw
an error.
Explanation:
Columns participating in a foreign key relationship must be defined
with the same length and scale. If not, then the
compiler will throw the following error:
Column
'FirstTable.vc_name' is not the same length or scale as referencing
column 'SecondTable.vc_person_name' in foreign key
'FK__SecondTab__vc_pe__54F81446'. Columns participating in a foreign
key relationship must be defined with the same length and scale.
No comments:
Post a Comment