It sounds like your table has no key. You should be able to simply try the INSERT
: if it’s a duplicate then the key constraint will bite and the INSERT
will fail. No worries: you just need to ensure the application doesn't see/ignores the error. When you say 'primary key' you presumably mean IDENTITY
value. That's all very well but you also need a key constraint (e.g. UNIQUE
) on your natural key.
Also, I wonder whether your procedure is doing too much. Consider having separate procedures for 'create' and 'read' actions respectively.