sqlupdateorinsert
A. 触发器里的都是什么意思啊
最基本的触发器是针对表的Insert、Update、Delete这三种操作来的。触发器可以建立在表上,也可以建立在视图上。建立在表上的触发器会在表内容发生改变时触发。建立在视图上的触发器会在视图内容改变时触发。注意,视图触发器仅会在明确对视图进行操作的sql语句执行时才会触发,当基本表的内容发生改变而引起视图内容变化时,不会触发视图触发器。
下面是建立表触发器的代码:
create
or
replace
trigger
tg_E_CONTACT
before
update
or
insert
or
delete
on
E_CONTACT
for
each
row
begin
if
inserting
then
insert
into
[email protected]
values
(:new.TELEPHONE,
:new.EMPLOYEEID,
:new.STATUS);
else
if
updating
then
update
[email protected]
s
set
s.TELEPHONE
=
:new.TELEPHONE,
s.EMPLOYEEID
=
:new.EMPLOYEEID,
s.STATUS
=
:new.STATUS
where
s.employeeid
=
:old.employeeid;
else
if
deleting
then
delete
from
[email protected]
s
where
s.employeeid
=
:old.employeeid;
end
if;
end
if;
end
if;
end;
下面是建立视图触发器的代码:(注意里面的instead
of)
create
or
replace
trigger
tg_E_CONTACT
before
instead
of
update
or
instead
of
insert
or
instead
of
delete
on
E_CONTACT
for
each
row
begin
if
inserting
then
insert
into
[email protected]
values
(:new.TELEPHONE,
:new.EMPLOYEEID,
:new.STATUS);
else
if
updating
then
update
[email protected]
s
set
s.TELEPHONE
=
:new.TELEPHONE,
s.EMPLOYEEID
=
:new.EMPLOYEEID,
s.STATUS
=
:new.STATUS
where
s.employeeid
=
:old.employeeid;
else
if
deleting
then
delete
from
[email protected]
s
where
s.employeeid
=
:old.employeeid;
end
if;
end
if;
end
if;
end;
B. 总是报超出最大打开游标问题,刚启动tomcat时,是好用的,启动一定时间后,就开始报错
需要日志看的原因......
这个原因,字面意思是1000无法启动,启动时间需要更多的超过1000个,然后再配置的最大超时。
C. spring的事务管理和HibernateTemplate中bulkupdate的问题
Could not synchronize database state with session
错在这里,好像是session问题,因为spring已经管理了session。所以就不要在写了。
D. c#将结果写入access
Console.WriteLine是将结果显示到dos窗体中,不是存入到access数据库中吧,要想把结果存入到access数据库中可以这样进行:
1、首先添加引用:using System.Data.OleDb;
2、给定连接字符串,如:public string str="provider=Microsoft.Jet.oledb.4.0;data source=数据库的路径;"
3、接着写一个对数据表进行操作的函数:
public bool UpdateOrInsert(string sql)
{
OleDbConnection myConn = new OleDbConnection(str); //这里的str即上面的str
try
{
myConn.Open();
OleDbCommand cmd = new OleDbCommand(sql, myConn);
cmd.ExecuteNonQuery();
myConn.Close();
return true;
}
catch
{
myConn.Close();
return false;
}
}
4、完成以上3步后,就可以对数据库进行操作了,例如要将运算得到的结果r,g,b及gray存入到数据库中名为RGB的数据表,可以这样进行:
4.1 写一条插入数据的sql语句: string sql="insert into RGB (Red,Green,Blue) values (' " + r.ToString()+" ',' " + g.ToString() + " ',' " + b.ToString() + " ',' " + gray.ToString() + " ')"
4.2 将sql作为传入参数,利用之前写的函数完成数据的插入:UpdateOrInsert(sql);
E. 可视化触发器如何创建
最基本的触发器是针对表的Insert、Update、Delete这三种操作来的。触发器可以建立在表上,也可以建立在视图上。建立在表上的触发器会在表内容发生改变时触发。建立在视图上的触发器会在视图内容改变时触发。注意,视图触发器仅会在明确对视图进行操作的SQL语句执行时才会触发,当基本表的内容发生改变而引起视图内容变化时,不会触发视图触发器。下面是建立表触发器的代码:create
or
replace
trigger
tg_E_CONTACTbefore
update
or
insert
or
delete
on
E_CONTACTfor
each
rowbeginif
inserting
theninsert
into
[email protected](:new.TELEPHONE,
:new.EMPLOYEEID,
:new.STATUS);elseif
updating
thenupdate
[email protected]
sset
s.TELEPHONE
=
:new.TELEPHONE,s.EMPLOYEEID
=
:new.EMPLOYEEID,s.STATUS
=
:new.STATUSwhere
s.employeeid
=
:old.employeeid;elseif
deleting
thendelete
from
[email protected]
swhere
s.employeeid
=
:old.employeeid;end
if;end
if;end
if;end;下面是建立视图触发器的代码:(注意里面的instead
of)create
or
replace
trigger
tg_E_CONTACTbefore
instead
of
update
or
instead
of
insert
or
instead
of
delete
on
E_CONTACTfor
each
rowbeginif
inserting
theninsert
into
[email protected](:new.TELEPHONE,
:new.EMPLOYEEID,
:new.STATUS);elseif
updating
thenupdate
[email protected]
sset
s.TELEPHONE
=
:new.TELEPHONE,s.EMPLOYEEID
=
:new.EMPLOYEEID,s.STATUS
=
:new.STATUSwhere
s.employeeid
=
:old.employeeid;elseif
deleting
thendelete
from
[email protected]
swhere
s.employeeid
=
:old.employeeid;end
if;end
if;end
if;end;
F. 怎么在sql2000查找触发器
最基本的触发器是针对表的insert、update、delete这三种操作来的。触发器可以建立在表上,也可以建立在视图上。建立在表上的触发器会在表内容发生改变时触发。建立在视图上的触发器会在视图内容改变时触发。注意,视图触发器仅会在明确对视图进行操作的sql语句执行时才会触发,当基本表的内容发生改变而引起视图内容变化时,不会触发视图触发器。
下面是建立表触发器的代码:
create
or
replace
trigger
tg_e_contact
before
update
or
insert
or
delete
on
e_contact
for
each
row
begin
if
inserting
then
insert
into
[email protected]
values
(:new.telephone,
:new.employeeid,
:new.status);
else
if
updating
then
update
[email protected]
s
set
s.telephone
=
:new.telephone,
s.employeeid
=
:new.employeeid,
s.status
=
:new.status
where
s.employeeid
=
:old.employeeid;
else
if
deleting
then
delete
from
[email protected]
s
where
s.employeeid
=
:old.employeeid;
end
if;
end
if;
end
if;
end;
下面是建立视图触发器的代码:(注意里面的instead
of)
create
or
replace
trigger
tg_e_contact
before
instead
of
update
or
instead
of
insert
or
instead
of
delete
on
e_contact
for
each
row
begin
if
inserting
then
insert
into
[email protected]
values
(:new.telephone,
:new.employeeid,
:new.status);
else
if
updating
then
update
[email protected]
s
set
s.telephone
=
:new.telephone,
s.employeeid
=
:new.employeeid,
s.status
=
:new.status
where
s.employeeid
=
:old.employeeid;
else
if
deleting
then
delete
from
[email protected]
s
where
s.employeeid
=
:old.employeeid;
end
if;
end
if;
end
if;
end;