Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8979

How can I add values ​​to these two tables relate to each other

$
0
0

create table tblA
(
id int identity(1,1) primary key,
name varchar(50) not null,
CountryId int not null
)

create table tblB
(

id int identity(1,1) primary key,
countryname varchar(25) not null
)

alter table tblA add constraint tblA_CountryId_FK
foreign key (CountryId) references tblB(id)

How i can now add values to tblA and tblB?

If i try get an error :

The INSERT statement conflicted with the FOREIGN KEY constraint "tblA_CountryId_FK". The conflict occurred in database "Sample", table "dbo.tblB", column 'id'.

Thanks :)

Massimo


www.Photoballot.net


Viewing all articles
Browse latest Browse all 8979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>