Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Prevent insert more than one record in a table.
Fri, Feb 22 2013 2:29 PMPermanent Link

Vitor Martins

Pregitzer & Ca., Lda

How can I prevent insert more than one record in a table. At DataBase level.

Best regads
Vitor Martins
Sat, Feb 23 2013 4:32 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Vitor

>How can I prevent insert more than one record in a table. At DataBase level.

Do you mean one record at a time, one record ever or....

Roy Lambert [Team Elevate]
Sat, Feb 23 2013 1:41 PMPermanent Link

Barry

<How can I prevent insert more than one record in a table. At DataBase level.>

Victor,

If you want a table to contain only 1 row at most, you will need to create a Before Insert trigger and see if the table is empty. If not, then raise an exception to disallow a new row from from being inserted.

This allows the row to be deleted, or edited, but won't allow the table to have more than 1 row in it.

Barry
Sat, Feb 23 2013 2:37 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Vitor,

<< How can I prevent insert more than one record in a table. At DataBase
level. >>

Here's what it would look like as a trigger:

CREATE TRIGGER "PreventInsert" BEFORE INSERT ON "SingleRow"
BEGIN
  DECLARE TestCursor CURSOR FOR TestStatement;
  PREPARE TestStatement FROM 'TABLE SingleRow';
  OPEN TestCursor;

  IF (ROWCOUNT(TestCursor) >= 1) THEN
     ABORT;
  END IF;
END

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Feb 25 2013 3:08 PMPermanent Link

Vitor Martins

Pregitzer & Ca., Lda


Works fine, thanks

Best regards
Vitor Martins

"Tim Young [Elevate Software]" wrote:

Vitor,

<< How can I prevent insert more than one record in a table. At DataBase
level. >>

Here's what it would look like as a trigger:

CREATE TRIGGER "PreventInsert" BEFORE INSERT ON "SingleRow"
BEGIN
  DECLARE TestCursor CURSOR FOR TestStatement;
  PREPARE TestStatement FROM 'TABLE SingleRow';
  OPEN TestCursor;

  IF (ROWCOUNT(TestCursor) >= 1) THEN
     ABORT;
  END IF;
END

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Image