I have a table where I relate Authors and Books as shown below, what I want is that when trying to insert a new relationship, first check if said relationship already exists and if it already exists, return a message, well the problem is not programming, my problem is that I do not know how to make a function in sql that returns either a bool or a 1 or 0 to know if it exists or not, the purpose of the function being in sql is because in dapper I only send the script to be executed and It should return the value I want and I could compare it with that within the program. If I don't explain myself well, please tell me, I'll be on the lookout. Finally I want a function or SP that tells me if the relationship already exists or not. I have no code as I haven't found any example that I could understand to do what I want.
Based on what you specifically require, getting a response to see if the relationship already exists can be done using stored procedures.
Case of existence of relationship
It is tested with the following query:
Resulting in:
Case of NO existence of relationship
It is tested with the following query:
Resulting in:
After that, you can store that 1 or 0 in a variable to be able to proceed to use another stored procedure that is to insert the new relation.
I don't know if something like this will help you:
I could not specify more because you did not put the fields of your tables or some reference query, even so I hope this helps in some way