¡¾SQL SERVER Êý¾Ý¿âʵÓÃSQLÓï¾ä¡¿
¡¾SQL SERVER Êý¾Ý¿âʵÓÃSQLÓï¾ä¡¿
1.°´ÐÕÊϱʻÅÅÐò:
Select * from TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as
2.·ÖÒ³SQLÓï¾ä
select * from(select (row_number() OVER (ORDER BY tab.ID Desc)) as rownum,tab.* from ±íÃû As tab) As t where rownum between ÆðʼλÖà And ½áÊøλÖÃ
3.»ñÈ¡µ±Ç°Êý¾Ý¿âÖеÄËùÓÐÓû§±í
select * from sysobjects where xtype='U' and category=0
4.»ñȡijһ¸ö±íµÄËùÓÐ×Ö¶Î
select name from syscolumns where id=object_id('±íÃû')
5.²é¿´Óëijһ¸ö±íÏà¹ØµÄÊÓͼ¡¢´æ´¢¹ý³Ì¡¢º¯Êý
select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%±íÃû%'
6.²é¿´µ±Ç°Êý¾Ý¿âÖÐËùÓд洢¹ý³Ì
select name as ´æ´¢¹ý³ÌÃû³Æ from sysobjects where xtype='P'
7.²éѯÓû§´´½¨µÄËùÓÐÊý¾Ý¿â
select * from master..sysdatabases D where sid not in(select sid from master..syslogins where name='sa')
»òÕß
select dbid, name AS DB_NAME from master..sysdatabases where sid <> 0x01
8.²éѯijһ¸ö±íµÄ×ֶκÍÊý¾ÝÀàÐÍ
select column_name,data_type from information_schema.columns
where table_name = '±íÃû'
9.ʹÓÃÊÂÎñ
ÔÚʹÓÃһЩ¶ÔÊý¾Ý¿â±íµÄÁÙʱµÄSQLÓï¾ä²Ù×÷ʱ£¬¿ÉÒÔ²ÉÓÃSQL SERVERÊÂÎñ´¦Àí£¬·ÀÖ¹¶ÔÊý¾Ý²Ù×÷ºó·¢ÏÖÎó²Ù×÷ÎÊÌâ
¿ªÊ¼ÊÂÎñ
Begin tran
Insert Into TableName Values(…)
SQLÓï¾ä²Ù×÷²»Õý³££¬Ôò»Ø¹öÊÂÎñ¡£
»Ø¹öÊÂÎñ
Rollback tran
SQLÓï¾ä²Ù×÷Õý³££¬ÔòÌá½»ÊÂÎñ£¬Êý¾ÝÌá½»ÖÁÊý¾Ý¿â¡£
Ìá½»ÊÂÎñ
Commit tran
10. °´È«ÎÄÆ¥Å䷽ʽ²éѯ
×Ö¶ÎÃû LIKE N'%[^a-zA-Z0-9]China[^a-zA-Z0-9]%'
OR ×Ö¶ÎÃû LIKE N'%[^a-zA-Z0-9]China'
OR ×Ö¶ÎÃû LIKE N'China[^a-zA-Z0-9]%'
OR ×Ö¶ÎÃû LIKE N'China
11£®¼ÆËãÖ´ÐÐSQLÓï¾ä²éѯʱ¼ä
declare @d datetime
set @d=getdate()
select * from SYS_ColumnProperties select [Óï¾äÖ´Ðл¨·Ñʱ¼ä(ºÁÃë)]=datediff(ms,@d,getdate())
12¡¢ËµÃ÷£º¼¸¸ö¸ß¼¶²éѯÔËËã´Ê
A£º UNION ÔËËã·û
UNION ÔËËã·ûͨ¹ý×éºÏÆäËûÁ½¸ö½á¹û±í£¨ÀýÈç TABLE1 ºÍ TABLE2£©²¢ÏûÈ¥±íÖÐÈκÎÖظ´ÐжøÅÉÉú³öÒ»¸ö½á¹û±í¡£µ± ALL Ëæ UNION Ò»ÆðʹÓÃʱ£¨¼´ UNION ALL£©£¬²»Ïû³ýÖظ´ÐС£Á½ÖÖÇé¿öÏ£¬ÅÉÉú±íµÄÿһÐв»ÊÇÀ´×Ô TABLE1 ¾ÍÊÇÀ´×Ô TABLE2¡£
B£º EXCEPT
Ïà¹ØÎĵµ£º
¡¡ÔÚSQL Server 2005Êý¾Ý¿âÖÐʵÏÖ×Ô¶¯±¸·ÝµÄ¾ßÌå²½Öè:
¡¡¡¡1¡¢´ò¿ªSQL Server Management Studio
¡¡¡¡2¡¢Æô¶¯SQL Server´úÀí
¡¡¡¡3¡¢µã»÷×÷Òµ->н¨×÷Òµ
¡¡¡¡4¡¢"³£¹æ"ÖÐÊäÈë×÷ÒµµÄÃû³Æ
¡¡¡¡5¡¢Ð½¨²½Ö裬ÀàÐÍÑ¡T-SQL£¬ÔÚÏÂÃæµÄÃüÁîÖÐÊäÈëÏÂÃæÓï¾ä£¨Çë¸ù¾Ý×Ô¼ºµÄʵ¼ÊÇé¿ö¸ü¸Ä£¬D:\sql2005\\back\¸ÄΪ×Ô¼ºµÄ±¸· ......
Create PROCEDURE UpdateWanjun
@UserName nvarchar(500),
@UserPassword nvarchar(500),
@ReturnVal int output
AS
--Set XAcT_ABORT ON
Begin Transaction T
Update admins set UserPassword = @UserPassword wh ......
1 --´ÓTable ±íÖÐÈ¡³öµÚ m Ìõµ½µÚ n ÌõµÄ¼Ç¼£º(Not In °æ±¾)
2
3 SELECT TOP n-m+1 *
4 from Table
5 WHERE (id NOT IN (SELECT TOP m-1 id from Table ))
6
7
8 --´ÓTABLE±íÖÐÈ¡³öµÚmµ½nÌõ¼Ç¼ (Exists°æ±¾)
9
10 SELECT TOP n-m+1 * from ......
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--SQLÊý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER TABLE --ÐÞ¸ÄÊý¾Ý¿â±í½á¹¹
CREATE VIEW --´´½¨Ò»¸öÊÓͼ
DROP VIEW --´ÓÊý¾Ý¿âÖÐɾ³ýÊ ......
¡¡Ò»¡¢±¸·ÝÊý¾Ý¿â
¡¡¡¡1¡¢´ò¿ªSQLÆóÒµ¹ÜÀíÆ÷£¬ÔÚ¿ØÖÆ̨¸ùĿ¼ÖÐÒÀ´Îµã¿ªMicrosoft SQL Server
¡¡¡¡2¡¢SQL Server×é-->Ë«»÷´ò¿ªÄãµÄ·þÎñÆ÷-->Ë«»÷´ò¿ªÊý¾Ý¿âĿ¼
¡¡¡¡3¡¢Ñ¡ÔñÄãµÄÊý¾Ý¿âÃû³Æ£¨ÈçÂÛ̳Êý¾Ý¿âForum£©-->È»ºóµãÉÏÃæ²Ëµ¥ÖеŤ¾ß-->Ñ¡Ôñ±¸·ÝÊý¾Ý¿â
¡¡¡¡4¡¢±¸·ÝÑ¡ÏîÑ¡ÔñÍêÈ«±¸·Ý£¬Ä¿µÄÖеı ......