SQL, Why do I get this error when creating the reports table?

EDWARD FABIAN TAPIERO GOMEZ

SQL, Why do I get this error when creating the reports table?

This is error

There are no primary keys or candidates in the referenced table ('Patients') that match the list of columns referenced in the foreign key 'FK__Reports__Patient__2B3F6F97'. Mens. 1750, Level 16, State 0, Line 29 Could not create restriction or index. See previous errors.

This is my Query

create database kanirmaConnections;
use kanirmaConnections
go

create table Messages(
  Id int identity primary key,
  Recieve varchar(100),
  Sender varchar(100),
  Message varchar(100),
  Idf int,
  foreign key(Idf) references UserData(Id),
);

create table Patients(
  PatientID int identity,
  Name varchar(100),
  Age int,
  Gender varchar(20),
  BG varchar(100),
  problem varchar(100),
  Address varchar(100),
  city varchar(20),
  pincode int,
  Idf int,
  foreign key(Idf) references UserData(Id),
);

create table Reports(
  Id int identity,
  PatientName varchar(100),
  disease varchar(30),
  briefExplain varchar(100),
  symptoms varchar(100),
  Admited varchar(100),
  Idf int,
  PatientIDf int,
  primary key(Id, Idf, PatientIDf),
  foreign key(Idf) references UserData(Id),
  foreign key(PatientIDf) references Patients(PatientID),
);

create table UserData(
  Id int identity primary key,
  Username varchar(20),
  password varchar(30),
  Email varchar(100),
  job varchar(20),
);

/**********************
primary key (Id_usuario),
foreign key (Id_especialidadf) references Especialidad (Id_especialidad),
foreign key (Id_rolf) references Roles (Id_rol)
**********************/

Sergey Kalinichenko

You get this error because PatientId is declared as an integer identity, but it is not declared as primary key:

create table Patients(
  PatientID int identity primary key,
  Name varchar(100), --  ^^^^^^^^^^^
  Age int,
  Gender varchar(20),
  BG varchar(100),
  problem varchar(100),
  Address varchar(100),
  city varchar(20),
  pincode int,
  Idf int,
  foreign key(Idf) references UserData(Id),
);

Same problem applies to your Reports table.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why do I get a syntax error when creating a PostgreSQL function?

Why i get error when want insert to table in sql server?

Why do I get this 'GROUP BY' error when using 'UPDATE' (SQL)?

Why do I get a "cannot execute LOCK TABLE during recovery error" when I run my SQL query?

Why do I get the error "Cannot store non-PrivateKeys" when creating an SSL Socket in Java?

Why do I get error when ifstream is creating file with string read from keyboard?

Why do I get a 'list index out of range' error here when creating an instance of a class?

Why do I get an error when creating a new module in Android Studio?

Why do I get this error in SQL Server?

Why do I get error in SQL query?

Why do I get error code 1064 when I use count in derived table?

Why do I get an Error when I try to rename a table after FROM?

Why do i get a laravel error while creating a new project?

Why do i get this compilation error in creating JComboBox object?

why do i get this error creating superuser django?

Why do I get a warning when creating a custom slash screen?

Why do I get a sql grammar error when I can successfully execute in MySQL

Why do I get an SQL parsing error when I use parameters?

Why do i get this error when trying to create a new table mysql?

Why do I get an invalid column name error when using a temp table twice?

Why do I get a "indexed columns are not unique" error when trying to add a UNIQUE INDEX to a SQLite Table?

Why do I get no such table error when installing Apache Airflow on Mac?

Why do I get a 11555 error on this SQL Server inline table valued function?

Why do I get Invalid Object Name for a SQL Server table, when the object is valid?

Why do I get an error when create a function but not when a variable?

Why do I get this error when I run 'bower install'?

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why do I get an error when I use transduce?

Why do i get this error when i connect snowflake and python