How to set the foreign key in sql server -


the query create primary key table is

create table users (     id int identity (3000, 1),     userid '08u1'+right('0000'+cast(id varchar(5)), 5) persisted,     username varchar(50),     lastname varchar(50),     location varchar(50),     constraint pk_users primary key (userid) ) 

and reference table is

create table addre (     ids int,     address varchar(50), ) 

i want userid primary key in users table reference table addre column ids foreign key how set that. know same data type used set foreign key. here how set data type ids...

change userid this

userid cast('08u1'+right('0000'+cast(id varchar(5)), 5) char(9)) persisted 

so char(9) datatype needed whichever way around want


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -