SQL ºÍ´æ´¢¹ý³Ì¼¶±ðµÄÊÂÎñ¼°ADO.NET¼¶±ðµÄÊÂÎñ
Êý¾Ý¿âÊÂÎñÊÇÆäËûÊÂÎñÄ£Ð͵Ļù´¡£¬µ±Ò»¸öÊÂÎñ´´½¨Ê±²»Í¬Êý¾Ý¿âϵͳ¶¼ÓÐ×Ô¼ºµÄ¹æ
Ôò¡£SQL Server ĬÈÏÔÚ×Ô¶¯Ìá½»µÄģʽϹ¤×÷£¬Ã¿¸öÓï¾äÖ´ÐÐÍêºó¶¼»áÁ¢¼´Ìá½»£»Óë´Ë¶ÔÕÕ
µÄÊÇ Oracle ÐèÒªÄã°üº¬Ò»¸öÌá½»Óï¾ä¡£µ«Êǵ±Ò»¸öÓï¾äͨ¹ý OLE DB Ö´ÐÐʱ£¬ËüÖ´ÐÐÍêºó
Ò»¸öÌá½»¶¯×÷»á±»¸½¼ÓÉÏÈ¥¡£ÀýÈ磺
DECLARE @TranName VARCHAR(20);
SELECT @TranName = 'MyTransaction';
BEGIN TRANSACTION @TranName;
GO
USE AdventureWorks;
GO
DELETE from AdventureWorks.HumanResources.JobCandidate
WHERE JobCandidateID = 13;
GO
COMMIT TRANSACTION MyTransaction;
GO
»òÕߣº
CREATE PROCEDURE Tran1
as
begin tran
set xact_abort on
Insert Into P_Category(CategoryId,Name)values('1','test1')
Insert Into P_Category(CategoryId,Name)values('2','test2')
commit tran
GO
set xact_abort on±íʾÓöµ½´íÎóÁ¢¼´»Ø¹ö¡£
µ±È»ÄãÒ²¿ÉÒÔÕâôд£º
CREATE PROCEDURE tran1
as
begin tran
Insert Into P_Category(CategoryId,Name)values('1','test1')
if(@@error<>0)
rollback tran
else
begin
Insert Into P_Category(CategoryId,Name)values('2','test2')
if(@@error<>0)
rollback tran
else
commit tran
end
GO
ADO.NET¼¶±ðµÄÊÂÎñ
string conString = "data source=127.0.0.1;database=codematic;user id=sa;
password=";
SqlConnection myConnection = new SqlConnection(conString);
myConnection.Open();
//Æô¶¯Ò»¸öÊÂÎñ
SqlTransaction myTrans =
Ïà¹ØÎĵµ£º
2.¸ù¾ÝOracle Êý¾Ý¿âscott ģʽϵÄemp ±íºÍdept ±í£¬Íê³ÉÏÂÁвÙ×÷£º
(1) ²éѯ20ºÅ²¿ÃŵÄËùÓÐÔ±¹¤ÐÅÏ¢£»
(2) ²éѯËùÓй¤ÖÖΪCLERK µÄÔ±¹¤µÄÔ±¹¤ºÅ¡¢Ô±¹¤ÃûºÍ²¿Ãźţ»
(3) ²éѯ½±½ðCOMM ¸ßÓÚ¹¤×ÊSAL µÄÔ±¹¤ÐÅÏ¢£»
  ......
MS-SQLÖÐsaµÇ¼ʧ°Ü:
¸Ã´íÎó²úÉúµÄÔÒòÊÇÓÉÓÚSQL ServerʹÓÃÁË"½ö Windows"µÄÉí·ÝÑéÖ¤·½Ê½,
Òò´ËÓû§ÎÞ·¨Ê¹ÓÃSQL ServerµÄµÇ¼ÕÊ»§£¨Èç sa £©½øÐÐÁ¬½Ó.½â¾ö·½·¨ÈçÏÂËùʾ:
1.ÔÚ·þÎñÆ÷¶ËʹÓÃÆóÒµ¹ÜÀíÆ÷,²¢ÇÒÑ¡Ôñ"ʹÓà Windows Éí·ÝÑéÖ¤"Á¬½ÓÉÏ SQL Server
²Ù×÷²½Öè:
ÔÚÆóÒµ¹ÜÀíÆ÷ÖÐ
--ÓÒ¼üÄãµÄ·þÎñÆ÷ʵÀý(¾ÍÊÇÄÇ ......
SQLServer2005ÀïʹÓÃwith encryptionÑ¡Ïî´´½¨µÄ´æ´¢¹ý³ÌÈÔÈ»ºÍsqlserver2000ÀïÒ»Ñù£¬¶¼ÊÇʹÓÃXOR½øÐÐÁ˵ļÓÃÜ¡£ºÍ2000²»Ò»ÑùµÄÊÇ£¬ÔÚ2005µÄϵͳ ±ísyscommentsÀïÒѾ²é²»µ½¼ÓÃܹýµÄÃÜÎÄÁË¡£Òª²éÃÜÎıØÐëʹÓÃDAC(רÓùÜÀíÔ±Á¬½Ó)Á¬½Óµ½Êý¾Ý¿âºó£¬ÔÚϵͳ±í sys.sysobjvalues²éѯ£¬¸Ã±íµÄÁÐimageval´æ´¢ÁËÏàÓ¦µÄÃÜÎÄ¡£¾ß ......
procedure Tform1.Button5Click(Sender: TObject);
var
p:pointer;
FrfStr:string;
begin
inherited;
Screen.Cursor:=MYCURSORWAITHAND;
with cdsPrint do
begin
Active:=false;
//Õâ¸öSQLÓÃÓÚ½«remarkÖеļǼºÏ²¢µ½Ò»Æ ......
SQL UNION ²Ù×÷·û
UNION ²Ù×÷·ûÓÃÓںϲ¢Á½¸ö»ò¶à¸ö SELECT Óï¾äµÄ½á¹û¼¯¡£
Çë×¢Ò⣬UNION ÄÚ²¿µÄ SELECT Óï¾ä±ØÐëÓµÓÐÏàͬÊýÁ¿µÄÁС£ÁÐÒ²±ØÐëÓµÓÐÏàËƵÄÊý¾ÝÀàÐÍ¡£Í¬Ê±£¬Ã¿Ìõ SELECT Óï¾äÖеÄÁеÄ˳Ðò±ØÐëÏàͬ¡£
SQL UNION Óï·¨
SELECT column_name(s) from table_name1
UNION
SELECT column_name(s) from tabl ......