´íÎóÌáʾ£¬ÓÐÒ»¸öÎļþÒѾ¹ÒÆ𣬱ØÐëÖØÐÂÆô¶¯¼ÆËã»ú¡£ÖØÐÂÆô¶¯£¬Ôٴΰ²×°ÈÔÈ»ÊÇͬÑùµÄÎÊÌâ¡£
×¢²á±í¼üÖµµÄÎÊÌâ¡£½â¾ö·½·¨£º
ֻҪɾ³ý\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\ϵÄPendingFileRenameOperations¼üÖµ£¬¾Í¿ÉÒÔÖØа²×°ÁË¡£
ɾ³ýºó°²×°£¬²»±ØÖØÐÂÆô¶¯¼ÆËã»ú¡£ ......
---Ò»¸öÔµĵÚÒ»Ìì
SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
--- ±¾ÖܵÄÐÇÆÚÒ»
SELECT DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)
---Ò»ÄêµÄµÚÒ»Ìì
SELECT DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
----¼¾¶ÈµÄµÚÒ»Ìì
SELECT DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)
----ÉϸöÔµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
----È¥ÄêµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))
----±¾ÔµÄ×îºóÒ»Ìì
SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
-----±¾ÔµĵÚÒ»¸öÐÇÆÚÒ»
select DATEADD(wk, DATEDIFF(wk,0,
dateadd(dd,6-datepart(day,getdate()),getdate())
&nb ......
---·µ»Ø±í´ïʽÖÐÖ¸¶¨×Ö·ûµÄ¿ªÊ¼Î»ÖÃ
select charindex('c','abcdefg',1)
---Á½¸ö×Ö·ûµÄÖµÖ®²î
select difference('bet','bit')
---×Ö·û×î×ó²àÖ¸¶¨ÊýÄ¿
select left('abcdef',3)
---·µ»Ø×Ö·ûÊý
select len('abcdefg')
--ת»»ÎªÐ¡×Ö·û
select lower('ABCDEFG')
--È¥×ó¿Õ¸ñºó
select ltrim(' abcdef')
---·µ»ØÖ¸¶¨µÚÒ»´Î³öÏֵĿªÊ¼Î»ÖÃ
select patindex('%_cd%','abcdef')
---Ìæ»»
select replace('abcdef','cd','xx')
---Ìæ»»¶à¸ö×Ö·û
select replace(replace('@22"33"','@',''),'"','')
--Öظ´±í´ïʽ
select replicate('abc',4)
---ÄæÏò±í´ïʽ
select reverse('abc')---cba
--·µ»ØÓÒ²àÖ¸¶¨ÊýÄ¿
select right('abcd',2)
---È¥ÓÒ¿Õ¸ñ
select rtrim('abcd ')
---soundex´úÂë
select soundex('abd')
--¿Õ¸ñ×Ö·û´®
select space(1)
---ת»»×Ö·û´®
select str(100)
---ɾ³ýÖ¸¶¨³¤¶È×Ö·û,²¢°ÑÖ¸¶¨Æðµã²åÈëÁíÒ»×Ö·û
select stuff('abcdef',2,4,'xxx')
---½ØÈ¡×Ö·û
select substring('abcdef',2,3)
---ת»»´óд
select upper('abc') ......
--Óï ¾ä ¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER TABLE --ÐÞ¸ÄÊý¾Ý¿â±í½á¹¹
CREATE VIEW --´´½¨Ò»¸öÊÓͼ
DROP VIEW --´ÓÊý¾Ý¿âÖÐɾ³ýÊÓͼ
CREATE INDEX --ΪÊý¾Ý¿â±í´´½¨Ò»¸öË÷Òý
DROP INDEX --´ÓÊý¾Ý¿âÖÐɾ³ýË÷Òý
CREATE PROCEDURE --´´½¨Ò»¸ö´æ´¢¹ý³Ì
DROP PROCEDURE --´ÓÊý¾Ý¿âÖÐɾ³ý´æ´¢¹ý³Ì
CREATE TRIGGER --´´½¨Ò»¸ö´¥·¢Æ÷
DROP TRIGGER --´ÓÊý¾Ý¿âÖÐɾ³ý´¥·¢Æ÷
CREATE SCHEMA --ÏòÊý¾Ý¿âÌí¼ÓÒ»¸öÐÂģʽ
DROP SCHEMA --´ÓÊý¾Ý¿âÖÐɾ³ýÒ»¸öģʽ
CREATE DOMAIN --´´½¨Ò»¸öÊý¾ÝÖµÓò
ALTER DOMAIN --¸Ä±äÓò¶¨Òå
DROP DOMAIN --´ÓÊý¾Ý¿âÖÐɾ³ýÒ»¸öÓò
--Êý¾Ý¿ØÖÆ
GRANT --ÊÚÓèÓû§·ÃÎÊȨÏÞ
DENY --¾Ü¾øÓû§·ÃÎÊ
REVOKE --½â³ýÓû§·ÃÎÊȨÏÞ
--ÊÂÎñ¿ØÖÆ
COMMIT --½áÊøµ±Ç°ÊÂÎñ
ROLLBACK --ÖÐÖ¹µ±Ç°ÊÂÎñ
SET TRANSACTION --¶¨Ò嵱ǰÊÂÎñÊý¾Ý·ÃÎÊÌØÕ÷
--³ÌÐò»¯SQL
DECLARE --Ϊ²éѯÉ趨Óαê
EXPLAN --Ϊ²éѯÃèÊöÊý¾Ý·ÃÎʼƻ®
OPEN --¼ìË÷²éÑ ......
MS SQL Server 2008 ÔÚ½¨Íê±íºó£¬Èç¹ûÒª²åÈëÈÎÒâÁУ¬ÔòÌáʾ£º
µ±Óû§ÔÚÔÚSQL Server 2008ÆóÒµ¹ÜÀíÆ÷Öиü¸Ä±í½á¹¹Ê±£¬±ØÐëÒªÏÈɾ³ýÔÀ´µÄ±í£¬È»ºóÖØд´½¨ÐÂ±í£¬²ÅÄÜÍê³É±íµÄ¸ü¸Ä£¬Èç¹ûÇ¿Ðиü¸Ä»á³öÏÖÒÔÏÂÌáʾ£º²»ÔÊÐí±£´æ¸ü¸Ä¡£ÄúËù×öµÄ¸ü¸ÄÒªÇóɾ³ý²¢ÖØд´½¨ÒÔÏÂ±í¡£Äú¶ÔÎÞ·¨ÖØд´½¨µÄ±ê½øÐÐÁ˸ü¸Ä»òÕßÆôÓÃÁË“×èÖ¹±£´æÒªÇóÖØд´½¨±íµÄ¸ü¸Ä”Ñ¡Ïî¡£
Èç¹ûҪȥµô´ËÌáʾ£¬´ò¿ªSQL 2008 ÔÚ×îÉÏÃæ
¹¤¾ß-¡µÑ¡Ïî-¡µ×ó²àÓиö Éè¼ÆÆ÷(Designers)-¡µ±íÉè¼ÆÆ÷ºÍÊý¾Ý¿âÉè¼ÆÆ÷ -> ×èÖ¹±£´æÒªÇóÖØд´½¨±íµÄ¸ü¸Ä(ÓÒ²à) °Ñ¹³È¥ÖØÐÂÆô¶¯2008¼´¿É
......
ÓÐЩ³£¼ûµÄÎÊÌâÔÚÂÛ̳Öв»¶Ï³öÏÖ£¬²»·ÁÕûÀíһϡ£
ÒÔÏÂÓï¾äÊÇÔÚSQLServer2005ÉÏʵÏֵģ¬Ò»Ð©Óï¾äÎÞ·¨ÔÚSS2000ÉÏÖ´ÐС£
ÓÐÓÃÖ¸ÊýÊÇÎÒ¸ù¾ÝÕâ¸öÎÊÌâµÄ³£¼û³Ì¶È´òµÄ·Ö£¬½ö¹©²Î¿¼¡£Êµ¼ÊÉÏ£¬µ±ÄãÓöµ½ÁËÕâ¸öÎÊÌ⣬Õâ¸öÎÊÌâÄÄÅÂÔÙÉÙ¼û£¬½â¾ö·½°¸Ò²ÊǷdz£ÓÐÓõġ£
1. Éú³ÉÈô¸ÉÐмǼ
ÓÐÓÃÖ¸Êý£º¡ï¡ï¡ï¡ï¡ï
³£¼ûµÄÎÊÌâÀàÐÍ£º¸ù¾ÝÆðÖ¹ÈÕÆÚÉú³ÉÈô¸É¸öÈÕÆÚ¡¢Éú³ÉÒ»ÌìÖеĸ÷¸öʱ¼ä¶Î
¡¶SQL Server 2005¼¼ÊõÄÚÄ»£ºT-SQL²éѯ¡·×÷Õß½¨ÒéÔÚÊý¾Ý¿âÖд´½¨Ò»¸öÊý¾Ý±í£º
SQL code
--×ÔÈ»Êý±í1-1M
CREATE TABLE Nums(n int NOT NULL PRIMARY KEY CLUSTERED)
--ÊéÉϽéÉÜÁ˺ܶàÖÖÌî³ä·½·¨£¬ÒÔÏÂÊÇ×î¸ßЧµÄÒ»ÖÖ£¬ÐèÒªSS2005µÄROW_NUMBER()º¯Êý¡£
WITH B1 AS(SELECT n=1 UNION ALL SELECT n=1), --2
B2 AS(SELECT n=1 from B1 a CROSS JOIN B1 b), --4
B3 AS(SELECT n=1 from B2 a CROSS JOIN B2 b), --16
B4 AS(SELECT n=1 from B3 a CROSS JOIN B3 b), --256
B5 AS(SELECT n=1 from B4 a CROSS JOIN B4 b), --65536
CTE AS(SELECT r=ROW_NUMBER() OVER(ORDER BY (SELECT 1)) from B5 a CROSS JOIN B3 b) --65536 * 16
INSERT INTO Nums(n)
SELECT TOP(1000000) r from CTE ORDER B ......