I was trying to aply MySQL Syntax to SQL Server

Only Issues is on connect Foreign Key Payments Table which is has Payment_Method Varchar (Column) with reference Payment_Methods Table (Payment_Method_ID) . Payment_Method_ID - INT, Primary Key, Auto_Intrement.

Can someone help on this…

CREATE TABLE Payments
(
Payment_ID INT IDENTITY (1,1) PRIMARY KEY,
Client_ID INT NOT NULL,
Invoice_ID INT NOT NULL,
Date DATE NOT NULL,
Payment_Amount DECIMAL(9,2) NOT NULL,
Payment_Method TINYINT NOT NULL,
CONSTRAINT FK_Payments FOREIGN KEY (Client_ID)
REFERENCES Clients (Client_ID),
CONSTRAINT FK_Invoices FOREIGN KEY (Invoice_ID)
REFERENCES Invoices (Invoice_ID),
CONSTRAINT FK_PaymentsPayment_Methods FOREIGN KEY (Payment_Method)
REFERENCES Payment_Methods (Payment_Method_ID)
);

Output:
Msg 1778, Level 16, State 0, Line 73
Column ‘Payment_Methods.Payment_Method_ID’ is not the same data type as referencing column ‘Payments.Payment_Method’ in foreign key ‘FK_PaymentsPayment_Methods’.
Msg 1750, Level 16, State 1, Line 73
Could not create constraint or index. See previous errors.

The error message indicates that there’s a data type mismatch between the columns involved in the foreign key constraint. In your case, Payment_Method_ID in the Payment_Methods table is of type INT, whereas Payment_Method in the Payments table is of type TINYINT.

To resolve this issue, you need to make sure that the data types match.

1 Like

Thanks a lot! Apprecate for this help slight_smile: