Trigger to update table info

Started by Arvind Singhover 12 years ago3 messagesgeneral
Jump to latest
#1Arvind Singh
arvindps@hotmail.com

Hello friends,

I have a table with the following structure

Create table postablestatus

(

tablename
varchar(30) NOT NULL,

updatetime timestamp,

reccount
int,

size
int,

CONSTRAINT postablestatus_pkey PRIMARY KEY(tablename)

)
WITH (oids = false);

where
a) tablename - is the name of table where a record is inserted,updated or deleted
b) updatetime - the time when table was updated (w/o timezone)
c) reccount - records in table
d) size - bytesize of the table

--
for example, if a table called item_master had 1 record and a
new record is inserted and it's size is 2000 bytes

postablestatus must have a entry like

item_master 08/12/2013 12:40:00 2 2000
--

I request to know how to write a trigger in PLSQL so that the postablestatus
is updated whenever a record is inserted,updated or deleted in item_master

PLEASE NOTE : a new record must be created if the item_master is not present in postablestatus

thanks in advance
arvind

#2raghu ram
raghuchennuru@gmail.com
In reply to: Arvind Singh (#1)
Re: Trigger to update table info

On Mon, Aug 12, 2013 at 12:46 PM, Arvind Singh <arvindps@hotmail.com> wrote:

Hello friends,

I have a table with the following structure

Create table postablestatus

(

tablename varchar(30) NOT NULL,

updatetime timestamp,

reccount int,

size int,

CONSTRAINT postablestatus_pkey PRIMARY KEY(tablename)

) WITH (oids = false);

where
a) tablename - is the name of table where a record is inserted,updated or
deleted
b) updatetime - the time when table was updated (w/o timezone)
c) reccount - records in table
d) size - bytesize of the table

--
for example, if a table called item_master had 1 record and a
new record is inserted and it's size is 2000 bytes

postablestatus must have a entry like

item_master 08/12/2013 12:40:00 2 2000
--

I request to know how to write a trigger in PLSQL so that the
postablestatus
is updated whenever a record is inserted,updated or deleted in item_master

PLEASE NOTE : a new record must be created if the item_master is not
present in postablestatus

You will get more information from below link for creation of audit

trigger:

http://wiki.postgresql.org/wiki/Audit_trigger

Thanks & Regards
Raghu Ram

#3Jayadevan M
maymala.jayadevan@gmail.com
In reply to: Arvind Singh (#1)
Re: Trigger to update table info

Hi,
In case you are not keen on getting the latest and really accurate
counts/size, you could just refer the views readily available -
http://stackoverflow.com/questions/2596670/how-do-you-find-the-row-count-for-all-your-tables-in-postgres
You won't get the updatetime, though.
Regards,
Jayadevan

On Mon, Aug 12, 2013 at 12:46 PM, Arvind Singh <arvindps@hotmail.com> wrote:

Show quoted text

Hello friends,

I have a table with the following structure

Create table postablestatus

(

tablename varchar(30) NOT NULL,

updatetime timestamp,

reccount int,

size int,

CONSTRAINT postablestatus_pkey PRIMARY KEY(tablename)

) WITH (oids = false);

where
a) tablename - is the name of table where a record is inserted,updated or
deleted
b) updatetime - the time when table was updated (w/o timezone)
c) reccount - records in table
d) size - bytesize of the table

--
for example, if a table called item_master had 1 record and a
new record is inserted and it's size is 2000 bytes

postablestatus must have a entry like

item_master 08/12/2013 12:40:00 2 2000
--

I request to know how to write a trigger in PLSQL so that the
postablestatus
is updated whenever a record is inserted,updated or deleted in item_master

PLEASE NOTE : a new record must be created if the item_master is not
present in postablestatus

thanks in advance
arvind