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;