How to Make Fixed Row Table

30 pts.
Tags:
SQL Server
SQL Server 2008
SQL tables
Hi all My question is that i want to make the table which will accept only 500 row. even it could not accept 501th row. i mean to say i can't accept at the time of insertion not on fetch time

Software/Hardware used:
sql server 2008

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could use a CHECK constraint.

Semething like this:

<pre>CREATE FUNCTION CheckFnctn()
RETURNS int
AS
BEGIN
DECLARE @retval int
SELECT @retval = COUNT(*) FROM yourTable
RETURN @retval
END;
GO
ALTER TABLE yourTable
ADD CONSTRAINT chkRowCount CHECK (dbo.CheckFnctn() <= 500 );
GO</pre>

-CarlosDL

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • DotnetDevoloper
    Thank it is Working U r the Mind Blowing Man I want to give u a complement : I want to be like u if u help me tanks.................................. my id is : "computerboy8603@yahoo.com" this is not a big metter but i want to apriciate ur creativity
    30 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following