June 4, 2008 at 5:29 am
Dear All,
Could any one tell me can I restrict a table where i can insert only 50 records?
Sunil,
June 4, 2008 at 6:36 am
One way that comes to mind is to have a tinyint column that you increment manually as you insert data. Put two constraints on the column, one to make it unique and one to verify that the values are < 51.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 4, 2008 at 10:33 am
How bout a constraint that if Count(*) >=50 then deny
Or insert trigger rather. Not sure if you can do that with a constraint.
You can do it with a check constraint. Something like:
June 4, 2008 at 10:46 am
If you used a trigger wouldn't it have to be an "instead of" trigger?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 4, 2008 at 10:56 am
Grant Fritchey (6/4/2008)
If you used a trigger wouldn't it have to be an "instead of" trigger?
Instead Of would certainly be cleaner, since it would *prevent* or cancel a transaction before it happens, instead of *rolling back* a transaction. Technically though - you could do either.....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
June 4, 2008 at 11:34 am
Respect my grasshopper authorita 😉
June 4, 2008 at 11:48 am
When it comes to triggers... Absolutely!
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply