views:

118

answers:

2

I have a table with

GID
ID
DefaultA
DefaultB
DefaultC
DefaultD
DefaultE
DefaultF

my requirement is that there should always be one record in the database always.

In the front end if the end user tries to update its ok since he will update the existing record.But if he tries to enter a new record I must stop him.

+2  A: 

Create a primary key field, type tinyint, and set the constraint so that the value can only be "1" (oe you could use a unique index on the field). Set the field value to "1" for you single record. Then no other record can be entered.

Assuming GID is the primary key, here is sql code to add the constraint to your existing table:

ALTER TABLE dbo.address ADD CONSTRAINT
  single_record CHECK (GID = 1)
Ray
+1  A: 

Eliminate all Insert, delete permissions from all users...

or,

Add a trigger that rolls back any transaction that attempts to delete or insert a record.

Create Trigger MyTableEnsureSingleRowTrigger 
On MyTable for Insert, Delete 
As Rollback Transaction
Charles Bretana