Monday, 19 August 2013

How to set the foreign key in sql server

How to set the foreign key in sql server

The query to create the primary key table is
create table Users
(
Id int identity (3000, 1),
UserId as '08U1'+right('0000'+cast(Id as varchar(5)), 5) persisted,
UserName varchar(50),
LastName varchar(50),
Location varchar(50),
constraint PK_Users primary key (UserId)
)
And the reference table is
create table addre
(
Ids int,
address varchar(50),
)
I want to UserId primary key in the Users table to reference table addre
column Ids as foreign key how to set that. I know that the same data type
is only used to set foreign key. Where here how to set the data type for
the Ids...

No comments:

Post a Comment