Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

MSSQLÊý¾Ý¿âǶÌ×´æ´¢¹ý³ÌµÄÊÂÎñ¿ØÖÆ

   ÔÚMSSQL¹æ·¶ÖУ¬Ö§³ÖÊÂÎñǶÌ×£¬²»¹ýÔÚǶÌ×µ÷ÓÃ×Ó´æ´¢¹ý³Ìʱ£¬Òª»Ø¹öÊÂÎñ£¬Ðè°Ñ@@error´«¸ø×îÍâ²ãÊÂÎñ¡£¾ÙÀýÈçÏ£º
drop table testtb
go
create table testtb
(
 id int,name varchar(2)
)
go
--×Ó¹ý³Ì
drop proc proc_insert_sub
go
create proc proc_insert_sub
@errResult int out--·µ»Ø´íÎóÖµ
as begin
 declare @errsum int
 declare @transname varchar(20)
 set @transname='subtran'
 set @errsum=0
 --ÕýÈ·Êý¾Ý
    insert testtb values(1,'00')
 set @errsum=@errsum+@@error
 --´íÎóÊý¾Ý
 insert testtb values(2,'222')
 set @errsum=@errsum+@@error
 --ÕýÈ·Êý¾Ý
 insert testtb values(1,'11')
 set @errsum=@errsum+@@error
 set @errResult=@errsum
end
go
--Ö÷¹ý³Ì
drop proc proc_insert
go
create proc proc_insert
as begin
declare @errsum int
declare @errsum1 int
set @errsum=0
set @errsum1=0
  begin tran
  exec proc_insert_sub @errsum1 out
  print @errsum1
  set @errsum=@errsum+@errsum1
   print @errsum
print @@trancount
  if @errsum=0
 commit tran
  else
 ROLLBACK TRANSACTION  
end
go
/*Ö´ÐÐ
exec proc_insert
select * from testtb
*/


Ïà¹ØÎĵµ£º

»ùÓÚmssql °ÙÍò¼¶ Êý¾Ý ²éѯ ÓÅ»¯ ¼¼ÇÉÈýÊ®Ôò

1.¶Ô²éѯ½øÐÐÓÅ»¯£¬Ó¦¾¡Á¿±ÜÃâÈ«±íɨÃ裬Ê×ÏÈÓ¦¿¼ÂÇÔÚ where ¼° order by Éæ¼°µÄÁÐÉϽ¨Á¢Ë÷Òý¡£
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num is null
¿ÉÒÔÔÚnumÉÏÉèÖÃĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâÑù²éѯ£º
select id ......

MsSQL,MySQL,Oracle,Êý¾Ý¿âÁ¬½Ó×Ö¶Î

Ms sql 2000
drivername=com.microsoft.jdbc.sqlserver.SQLServerDriver
url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=books
username=sa
password=sa
MySQL
drivername=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/books
username=root
password=root
Oracle
drivername=orac ......

MSSQLÊý¾Ý¿âÊý¾ÝÀàÐÍ


 
    Êý¾ÝÀàÐÍ
 
 ÀàÐÍ
 
 ÃèÊö
 
bit
 
ÕûÐÍ
 
bit Êý¾ÝÀàÐÍÊÇÕûÐÍ£¬ÆäÖµÖ»ÄÜÊÇ0¡¢1»ò¿ÕÖµ¡£ÕâÖÖÊý¾ÝÀàÐÍÓÃÓÚ´æ´¢Ö»ÓÐÁ½ÖÖ¿ÉÄÜÖµµÄÊý¾Ý £¬ÈçYes »òNo¡¢True »òFa lse ¡¢On »òOff
int
 
ÕûÐÍ
 
int Êý¾ÝÀàÐÍ¿ÉÒÔ´æ´¢´Ó- 231( ......

MSSQLÊý¾Ý¿â±¸·Ý

1
¡¢
MSSQL
Êý¾Ý¿âµÄ¶¨ÆÚ×Ô¶¯±¸·Ý¼Æ»®
 
ͨ¹ýÆóÒµ¹ÜÀíÆ÷
ÉèÖÃÊý¾Ý¿âµÄ¶¨ÆÚ×Ô¶¯±¸·Ý¼Æ»®¡£
1
¡¢´ò¿ªÆóÒµ¹Ü
ÀíÆ÷£¬Ë«»÷´ò¿ªÄãµÄ·þÎñÆ÷
2
¡¢È»ºóµãÉÏÃæ
²Ëµ¥ÖеŤ¾ß
-->
Ñ¡ÔñÊý¾Ý¿âά»¤¼Æ»®Æ÷
3
¡¢ÏÂÒ»²½Ñ¡ÔñÒª½øÐÐ×Ô¶¯±¸·ÝµÄÊý¾Ý
-->
ÏÂÒ»²½¸üÐÂÊý¾ÝÓÅ»¯ÐÅÏ¢£¬ÕâÀïÒ»°ã²»ÓÃ×öÑ¡Ôñ
-->
ÏÂÒ ......

mssql row_number() partition ʹÓ÷½·¨Àí½â

Sql2005ÖÐʹÓÃow_number() partition½øÐзÖ×éʵÑ飬
SQL£º
select * from stu
select id,row_number() over (partition by snm order by id) from stu
½á¹û£º
id      snm
----------------
111 111V
111 111W
222 222N
333 3123
444 3123
555 3123
666 3232
777 3232
--·Ö×éºóµÄ½á¹û
id &n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ