CHECK Constraint For Allowing X Duplicates In Column

I wasn't sure if this is something that can be done in a CHECK constraint or if this requires a Stored Procedure for validating during insert, but can a constraint be created to allow only X amount of duplicates in a column, where X > 1?

Something along the lines of:

CONSTRAINT limiter_chk CHECK (SELECT COUNT(Id) AS Ct FROM Mytable WHERE Id = Id AND Count < 50)

I'm aware the the above isn't valid, but just trying to show the type of constraint I'm describing.

Answers


Business logic should be in the application, not the database.

However, you probably could write a TRIGGER to do what you are asking for.


Need Your Help

Has anyone ever seen this SQL Server Error? Failed Assertion = 'm_iteratorInSafeState'. I can't find anything online to help

sql-server sql-server-2005

We have a client running our .NET application which connects to SQL Server 2005 on the backend. A few weeks ago the database crashed and the whole server had to be rebooted. This happened again to...

Many small matrices speed-up for loops

python for-loop numpy scipy blas

I have a large coordinate grid (vectors a and b), for which I generate and solve a matrix (10x10) equation. Is there a way for scipy.linalg.solve to accept vector input? So far my solution was to r...