Technical Article

Ensure Table has only one row

,

Sometimes you have to create settings tables which only have one row. If you want to ensure table has only one row always and nobody can mess with it by deleting or inserting that row ,one way you can do it is to create triggers on the table to prevent deletes and inserts.

INSERT INTO dbo.venue_inventory_restriction_settings(sales_percent_threshold,minimum_venue_sales)

VALUES (85.00,25000);

 

CREATE TRIGGER dbo.venue_inventory_restriction_settings_delete_prevent

ON venue_inventory_restriction_settings INSTEAD OF DELETE

AS

BEGIN

    RAISERROR
('venue_inventory_restriction_settings
is a settings table.It must always have  one Row. (source = INSTEAD OF
DELETE)', 16,
1) 

END

GO

 

CREATE TRIGGER  dbo.venue_inventory_restriction_settings_insert_prevent

ON venue_inventory_restriction_settings INSTEAD OF INSERT

AS

BEGIN

    RAISERROR
('venue_inventory_restriction_settings
is a settings table.It must always have only one Row. (source = INSTEAD OF
INSERT)', 16,
1) 

END

GO

Rate

2.25 (8)

You rated this post out of 5. Change rating

Share

Share

Rate

2.25 (8)

You rated this post out of 5. Change rating