Why is this SQL server 2008 statement giving me an error?
CREATE TABLE [tbl_state_code](
[P_Id] smallint NOT NULL PRIMARY KEY IDENTITY,
[st_code] [varchar](2) NOT NULL);
CREATE TABLE [tbl_state_name](
[P_Id] smallint NOT NULL PRIMARY KEY IDENTITY,
[st_name] [varchar](20) NOT NULL,
FOREIGN KEY (st_code) REFERENCES tbl_state_code(st_code));
Error:
Msg 1769, Level 16, State 1, Line 6
Foreign key 'st_code' references invalid column 'st_code' in referencing table 'tbl_state_name'.
Msg 1750, Level 16, State 0, Line 6
Could not create constraint. See previous errors.
...
Go to the complete details ...