数据库触发器设置当数据更新(增加)时,另一张表也同时更新,但不知道为什么提示语法错误

数据库触发器设置当数据更新(增加)时,另一张表也同时更新,但不知道为什么提示语法错误,第1张

digoal=# create table a (aid int primary key, aname text, time timestamp);

NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "a_pkey" for table "a"

CREATE TABLE

digoal=# create table b (id int primary key, name text, time timestamp);

NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "b_pkey" for table "b"

CREATE TABLE

digoal=# create or replace function tg_a () returns trigger as $$

declare

begin

case TG_OP

when 'INSERT' then

insert into b(id,name,time) values (NEWaid, NEWaname, NEWtime);

when 'UPDATE' then

update b set id=NEWaid, name=NEWaname, time=NEWtime where id=OLDaid;

when 'DELETE' then

delete from b where id=OLDaid;

when 'TRUNCATE' then

truncate b;

else

return NULL;

end case;

return NULL;

end;

$$ language plpgsql;

digoal=# create trigger tg_a after INSERT OR DELETE OR UPDATE ON a for each row execute procedure tg_a();

CREATE TRIGGER

digoal=# create trigger tg_a_truncate after truncate ON a for each statement execute procedure tg_a();

CREATE TRIGGER

digoal=# insert into a select generate_series(1,10),'digoal',clock_timestamp();

INSERT 0 10

digoal=# select from a;

aid | aname | time

-----+--------+----------------------------

1 | digoal | 2013-02-03 18:59:37592479

2 | digoal | 2013-02-03 18:59:37592667

3 | digoal | 2013-02-03 18:59:37592674

4 | digoal | 2013-02-03 18:59:37592677

5 | digoal | 2013-02-03 18:59:3759268

6 | digoal | 2013-02-03 18:59:37592683

7 | digoal | 2013-02-03 18:59:37592686

8 | digoal | 2013-02-03 18:59:3759269

9 | digoal | 2013-02-03 18:59:37592693

10 | digoal | 2013-02-03 18:59:37592696

(10 rows)

digoal=# select from b;

id | name | time

----+--------+----------------------------

1 | digoal | 2013-02-03 18:59:37592479

2 | digoal | 2013-02-03 18:59:37592667

3 | digoal | 2013-02-03 18:59:37592674

4 | digoal | 2013-02-03 18:59:37592677

5 | digoal | 2013-02-03 18:59:3759268

6 | digoal | 2013-02-03 18:59:37592683

7 | digoal | 2013-02-03 18:59:37592686

8 | digoal | 2013-02-03 18:59:3759269

9 | digoal | 2013-02-03 18:59:37592693

10 | digoal | 2013-02-03 18:59:37592696

(10 rows)

digoal=# delete from a where aid=1;

DELETE 1

digoal=# select from b;

id | name | time

----+--------+----------------------------

2 | digoal | 2013-02-03 18:59:37592667

3 | digoal | 2013-02-03 18:59:37592674

4 | digoal | 2013-02-03 18:59:37592677

5 | digoal | 2013-02-03 18:59:3759268

6 | digoal | 2013-02-03 18:59:37592683

7 | digoal | 2013-02-03 18:59:37592686

8 | digoal | 2013-02-03 18:59:3759269

9 | digoal | 2013-02-03 18:59:37592693

10 | digoal | 2013-02-03 18:59:37592696

(9 rows)

digoal=# select from a;

aid | aname | time

-----+--------+----------------------------

2 | digoal | 2013-02-03 18:59:37592667

3 | digoal | 2013-02-03 18:59:37592674

4 | digoal | 2013-02-03 18:59:37592677

5 | digoal | 2013-02-03 18:59:3759268

6 | digoal | 2013-02-03 18:59:37592683

7 | digoal | 2013-02-03 18:59:37592686

8 | digoal | 2013-02-03 18:59:3759269

9 | digoal | 2013-02-03 18:59:37592693

10 | digoal | 2013-02-03 18:59:37592696

(9 rows)

digoal=# update a set aname='new' where aid=2;

UPDATE 1

digoal=# select from a where aid=2;

aid | aname | time

-----+-------+----------------------------

2 | new | 2013-02-03 18:59:37592667

(1 row)

digoal=# select from b where id=2;

id | name | time

----+------+----------------------------

2 | new | 2013-02-03 18:59:37592667

(1 row)

digoal=# truncate a;

TRUNCATE TABLE

digoal=# select from a;

aid | aname | time

-----+-------+------

(0 rows)

digoal=# select from b;

id | name | time

----+------+------

(0 rows)

在监管平台的数据库建设中,通过数据项、代码、类型、宽度、单位等定义,建立了一系列数据库文件,见表34至表332。

表34 数据库表格命名

续表

表35 实物地质资料目录清单表一(GS_APPLY)

续表

续表

表36 实物地质资料目录清单表二(GS_ADRILL)

表37 实物地质资料目录清单表三(GS_ASURVEY)

续表

表38 实物地质资料移交清单(GS_LIST)

表39 实物地质资料移交内容(GS_CONTENT)

续表

表310 汇交用户表(GS_USER)

表311 角色表(GS_USER_ROLE)

表312 权限表(GS_USER_PERM)

表313 用户角色表(GS_USER_UROLE)

表314 角色权限表(GS_USER_ROPERM)

表315 国家汇交通知表(GS_S_MESG)

表316 国家通知表((GS_S_NOTICE)

表317 国家回执表((GS_S_RETURN)

表318 国家验收合格单表((GS_S_CHECK)

表319 省汇交通知表((GS_P_MESG)

表3 20 省验收合格单表(GS_P_CHECK)

表3 21 系统日志表(GS_LOG)

表3 22 行政区划(GS_PROVINCE)

表323 项目成果资料表(GS_CHENGGUO)

表324 原始资料表(GS_YUANSHI)

表325 原始资料确认表(GS_YSCHECK)

表326 项目成果确认表(GS_CGCHECK)

续表

表327 项目延期表(GS_DELAY)

表328 汇交凭证配号表(GS_PZPH)

表329 凭证表(GS_PINGZHENG)

续表

表330 项目资料转送表(GS_ZHUANSONG)

表331 项目转送通知表(GS_ZHUANSONGTZ)

表332 汇交验收表(GS_ACCEPT)

续表

addsql = "Insert into notice ('"&info&"',now())"

这一行改下,把列名加上

addsql = "Insert into notice (notice,notice_Date) values ('"&info&"',now())"

能格式规范点吗?

1查询newsadminAnn_Basinfo表中NOTICEDATE日期在2014-5-27之后并且notICETITLE字段中包含”停牌“字样的数据。

2连接newsadminANN_BASINFO、newsadminANN_RELCOLUMN、newsadminann_relcode三个表,并分别起别名为a、b、c(连接条件 aINFOCODE = bINFOCODE,aINFOCODE =cINFOCODE),然后从连接表中查询符合aSOURCETYPE字段以”35“开头、bcolumncode等于'001002008'、anoticetitle字段中包含”召开。。。股东大会“条件的数据,结果 以anoticedate 降序排列。

3连接表newsadminANN_BASINFO、表newsadminANN_RELCOLUMN(连接条件aINFOCODE = bINFOCODE),分别起别名a、b ,查询符合SOURCETYPE 字段以”35“开头、bcolumncode等于'001002008'且anoticetitle字段中包含”召开、、、股东大会“字样,anoticetitle不包含”更正“字样、anoticetitle字段不包含”补充“条件的数据,其结果按 anoticedate降序排列!

代码复制的太乱了! 看完太累了,其中有可能有错,有分歧再问我,如果对你有帮助,望采纳!!!!!!!!!!!

以上就是关于数据库触发器设置当数据更新(增加)时,另一张表也同时更新,但不知道为什么提示语法错误全部的内容,包括:数据库触发器设置当数据更新(增加)时,另一张表也同时更新,但不知道为什么提示语法错误、数据库文件格式、PHP中Notice的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10147310.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存