@Clusters = qw/ Cluster_ID INT IDENTITY(1,1) PRIMARY KEY, Cluster_Name VARCHAR(50) not NULL unique, DC_ID INT not NULL CONSTRAINT Cluster_2_DC FOREIGN KEY REFERENCES dbo.Data_Centers(DC_ID)/;
@Hosts = qw/Host_ID INT IDENTITY(1,1) PRIMARY KEY, Host_Name NVARCHAR(50) NULL, Cluster_ID int CONSTRAINT Host_2_Cluster FOREIGN KEY REFERENCES dbo.Clusters(Cluster_ID), DC_ID int not NULL CONSTRAINT Host_2_DC FOREIGN KEY REFERENCES dbo.Data_Centers(DC_ID)/;
####
sub sql_write
{
my ($input, $id, $type) = @_;
if ($type eq 'SRV')
{
printf "SERVER HOST: %s\n", $input->{name};
printf "ID DC: %s\n", $id->{DC};
printf "Cluster ID: %s\n", $id->{Cluster};
# insert data into Hosts table
$dbh->do("INSERT INTO Hosts (Host_Name,Cluster_ID,DC_ID) VALUES ('$input->{name}','$id->{Cluster}','$id->{DC}')");
}
}
####
my $rec_id = &sql_write($host_data,$Ids,"srv")
####
$Ids->{DC} = $dc_id;
$Ids->{Cluster} = $cluster_id;
####
DBD::ODBC::db do failed: [Microsoft][ODBC SQL Server Driver][SQL Server]The INSERT statement conflicted with the FOREIGN KEY cons
raint "Host_2_Cluster". The conflict occurred in database "DEV1111", table "dbo.Clusters", column 'Cluster_ID'. (SQL-23000) [er
was 1 now 1] [state was 23000 now 01000]
[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. (SQL-01000) at U:\Doccuments\test.pl line 104, line 1.