sqlÓï¾ä
SqlÓï¾ä
1. ˵Ã÷£º¸´ÖƱí(Ö»¸´Öƽṹ£¬Ô´±íÃû£ºa£¬Ð±íÃû£ºb) SQL:select * into bfrom awhere 1<>1;
2. ˵Ã÷£º¿½±´±í(¿½±´Êý¾Ý£¬Ô´±íÃû£ºa£¬Ä¿±ê±íÃû£ºb) SQL:insert into b(a, b, c)select d, e, ffrom b;
3. ˵Ã÷£ºÏÔʾÎÄÕ¡¢Ìá½»È˺Í×îºó»Ø¸´Ê±¼ä SQL:select a.title, a.username, b.adddatefrom table a,(select max(adddate) adddatefrom table where table.title=a.title) b ¡¡
4. ˵Ã÷£ºÍâÁ¬½Ó²éѯ(±íÃû1£ºa£¬±íÃû2£ºb) SQL:select a.a, a.b, a.c, b.c, b.d, b.ffrom aLEFT OUTJOIN bON a.a= b.c; ¡¡
5. ˵Ã÷£ºÈճ̰²ÅÅÌáÇ°Îå·ÖÖÓÌáÐÑ SQL:select * from Èճ̰²ÅÅwhere datediff(’’minute’’, f¿ª ʼʱ¼ä,getdate())>5 ¡¡¡¡¡¡¡¡
6. ˵Ã÷£ºÁ½ÕŹØÁª±í£¬É¾³ýÖ÷±íÖÐÒѾÔÚ¸±±íÖÐûÓеÄÐÅÏ¢ SQL:delete from infowhere not exists(select * from infobzwhere info.infid=infobz.infid );
¡¾SQL SERVER Êý¾Ý¿âʵÓÃSQLÓï¾ä¡¿
1.°´ÐÕÊϱʻÅÅÐò:Select * from TableNameOrder By CustomerName Collate Chinese_PRC_Stroke_ci_as
2.·ÖÒ³SQLÓï¾äselect * from(select (row_number()OVER (ORDER BY tab.IDDesc))as rownum,tab.* from ±íÃûAs tab)As twhere rownumbetween ÆðʼλÖÃAnd ½áÊøλÖÃ
3.»ñÈ¡µ±Ç°Êý¾Ý¿âÖеÄËùÓÐÓû§±íselect * from sysobjectswhere xtype='U' and category=0
4.»ñȡijһ¸ö±íµÄËùÓÐ×Ö¶Îselect namefrom syscolumnswhere id=object_id('±íÃû')
5.²é¿´Óëijһ¸ö±íÏà¹ØµÄÊÓͼ¡¢´æ´¢¹ý³Ì¡¢º¯Êýselect a.* from sysobjects a, syscomments bwhere a.id= b.idand b.text like '%±íÃû%'
6.²é¿´µ±Ç°Êý¾Ý¿âÖÐËùÓд洢¹ý³Ìselect nameas ´æ´¢¹ý³ÌÃû³Æfrom sysobjectswhere xtype='P'
7.²éѯÓû§´´½¨µÄËùÓÐÊý¾Ý¿âselect * from master..sysdatabases Dwhere sidnot in(select sidfrom master..sysloginswhere name='sa') »òÕßselect dbid, nameAS DB_NAME from master..sysdatabaseswhere sid<> 0x01
8.²éѯijһ¸ö±íµÄ×ֶκÍÊý¾ÝÀàÐÍselect column_name,data_typefrom information_schema.columnswhere table_name= '±íÃû'
9.ʹÓ
Ïà¹ØÎĵµ£º
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)¡¡¡¡
¡¡¡¡2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£¡¡¡¡
¡¡¡¡3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£¡¡¡¡
¡¡¡¡4¡¢ÄÚ´æ²»×ã¡¡¡¡
¡¡¡¡5¡¢ÍøÂçËÙ¶ÈÂý¡¡¡¡
¡¡¡¡6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó£¨¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿£©¡¡¡¡
¡¡¡¡7¡¢Ëø»òÕßËÀËø ......
DECLARE @dt datetime
SET @dt=GETDATE()
DECLARE @number int
SET @number=3
--1£®Ö¸¶¨ÈÕÆÚ¸ÃÄêµÄµÚÒ»Ìì»ò×îºóÒ»Ìì
--A. ÄêµÄµÚÒ»Ìì
SELECT CONVERT(char(5),@dt,120)+'1-1'
--B. ÄêµÄ×îºóÒ»Ìì
SELECT CONVERT(char(5),@dt,120)+'12-31'
--2£®Ö¸¶¨ÈÕÆÚËùÔÚ¼¾¶ÈµÄµÚÒ»Ìì»ò×îºóÒ»Ìì
--A. ¼¾¶ÈµÄµÚÒ»Ìì
SELECT CON ......
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃexecÖ´ÐÐ
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname from tab ......
1.¼ì²éÄãÊÇ·ñÏÞÖÆÁËÎļþÔö³¤:
ÆóÒµ¹ÜÀíÆ÷--ÓÒ¼üÄãµÄÊý¾Ý¿â--ÊôÐÔ--Êý¾ÝÎļþ--¿´¿´ÓÐûÓÐÉèÖÃÎļþµÄ×î´óÖµ
2.¼ì²éÄãµÄ´ÅÅÌ·ÖÇø¸ñʽ,Èç¹û²»ÊÇNTFS·ÖÇø,Ôò»áÓÐÏÞÖÆ,½«´ÅÅÌ·ÖÇø¸ñʽ¸Ä³ÉNTFS
&n ......
SQLÊý¾Ý»Ö¸´Èí¼þ Log Explorer for SQL Server v4.0
log explorerʹÓõļ¸¸öÎÊÌâ
¡¡¡¡1)¶ÔÊý¾Ý¿â×öÁËÍêÈ« ²îÒì ºÍÈÕÖ¾±¸·Ý
¡¡¡¡±¸·ÝʱѡÓÃÁËɾ³ýÊÂÎñÈÕÖ¾Öв»»î¶¯µÄÌõÄ¿
¡¡¡¡ÔÙÓÃLog explorer´òÊÔͼ¿´ÈÕ־ʱ
¡¡¡¡ÌáʾNo log recorders found that match the filter£¬would you like to view unfiltered ......