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

SQL×Ô¶¯É¾³ý±¸·ÝÎļþ

DECLARE  @sql varchar(8000)  
--ÏÂÃæÊÇɾ³ý15ÌìÇ°±¸·ÝÎļþµÄ´¦Àí  
set @sql='Del E:\Databasebackup\'  
@sql=@sql +rtrim(convert(varchar,getdate()-15,112))+'.bak'
Exec  master..xp_cmdshell   @sql  
DECLARE @DelFile Varchar(256)
set @DelFile='Del E:\Databasebackup\'
set @DelFile=@DelFile+'shya_DATA_'+Replace(convert(varchar(10),getdate()-28,120),'-','_')
Exec  master..xp_cmdshell  @DelFile
--ÅжÏÎļþÊÇ·ñ´æÔÚ
create table ##tb(a bit,b bit,c bit)
DECLARE @sql Varchar(256)
set @sql='E:\Databasebackup'+'shya_DATA_'+Replace(convert(varchar(10),getdate()-28,120),'-','_')
insert into ##tb
exec master..xp_fileexist @sql
--Îļþ´æÔÚÔòɾ³ý
if exists(select 1 from ##tb where a=1)
begin
DECLARE @DelFile Varchar(256)
set @DelFile='Del E:\Databasebackup\'
set @DelFile=@DelFile+'shya_DATA_'+Replace(convert(varchar(10),getdate()-28,120),'-','_')
Exec  master..xp_cmdshell  @DelFile
end
drop table ##tb
---×îдúÂë
--ÅжÏÎļþÊÇ·ñ´æÔÚ
create table ##tb(a bit,b bit,c bit)
DECLARE @DelFile Varchar(256)
set @DelFile='E:\Databasebackup\'
set @DelFile=@DelFile+'shya_DATA_'+Replace(convert(varchar(10),getdate()-28,120),'-','_')
insert into ##tb
exec master..xp_fileexist @DelFile
--Îļþ´æÔÚÔòɾ³ý
if exists(select 1 from ##tb where a=1)
begin
DECLARE @Delsql Varchar(256)
set @Delsql='Del '+ @DelFile
Exec  master..xp_cmdshell  @Delsql
end
drop table ##tb


Ïà¹ØÎĵµ£º

oracle SQLÐÔÄÜÓÅ»¯

ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£©      Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£ ......

ʹÓÃHibernate+MySql+native SQLµÄBUG,ÒÔ¼°½â¾ö°ì·¨

±¾À´ÊÇmssql+hibernate+native SQL Ó¦ÓõĺܺÍг
µ«Êǵ½ÁË°Ñmssql»»³Émysql£¬¾Í³öÁË´í(ͬÑùµÄÊý¾Ý½á¹¹ºÍÊý¾Ý)¡£
²éѯ·½·¨ÊÇ£º
String sql =
"select id XXX_ID from t_tab";
List<Map> list = session.createSQLQuery(sql)
.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
.list();
´í ......

SQL Union ÓëUnion AllÏê½â

1.Union
UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£
UNION µ ......

SQLÖÐJOINºÍUNIONÇø±ð¡¢Ó÷¨¼°Ê¾Àý


1.JOINºÍUNIONÇø±ð
join ÊÇÁ½Õűí×ö½»Á¬ºóÀïÃæÌõ¼þÏàͬµÄ²¿·Ö¼Ç¼²úÉúÒ»¸ö¼Ç¼¼¯£¬
unionÊDzúÉúµÄÁ½¸ö¼Ç¼¼¯(×Ö¶ÎÒªÒ»ÑùµÄ)²¢ÔÚÒ»Æ𣬳ÉΪһ¸öеļǼ¼¯ ¡£
JOINÓÃÓÚ°´ÕÕONÌõ¼þÁª½ÓÁ½¸ö±í£¬Ö÷ÒªÓÐËÄÖÖ£º
INNER JOIN£ºÄÚ²¿Áª½ÓÁ½¸ö±íÖеļǼ£¬½öµ±ÖÁÉÙÓÐÒ»¸öͬÊôÓÚÁ½±íµÄÐзûºÏÁª½ÓÌõ¼þʱ£¬ÄÚÁª½Ó²Å·µ»ØÐС£ÎÒÀí½âµÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ