SQL Server Êý¾Ý¿â¹ÜÀí³£ÓõÄSQLºÍT SQLÓï¾ä
1. ²é¿´Êý¾Ý¿âµÄ°æ±¾
select @@version
2. ²é¿´Êý¾Ý¿âËùÔÚ»úÆ÷²Ù×÷ϵͳ²ÎÊý
exec master..xp_msver
3. ²é¿´Êý¾Ý¿âÆô¶¯µÄ²ÎÊý
sp_configure
4. ²é¿´Êý¾Ý¿âÆô¶¯Ê±¼ä
select convert(varchar(30),login_time,120) from master..sysprocesses where spid=1
²é¿´Êý¾Ý¿â·þÎñÆ÷ÃûºÍʵÀýÃû
print 'Server Name: ' + convert(varchar(30),@@SERVERNAME)
print 'Instance: ' + convert(varchar(30),@@SERVICENAME)
5. ²é¿´ËùÓÐÊý¾Ý¿âÃû³Æ¼°´óС
sp_helpdb
ÖØÃüÃûÊý¾Ý¿âÓõÄSQL
sp_renamedb 'old_dbname', 'new_dbname'
6. ²é¿´ËùÓÐÊý¾Ý¿âÓû§µÇ¼ÐÅÏ¢
sp_helplogins
²é¿´ËùÓÐÊý¾Ý¿âÓû§ËùÊôµÄ½ÇÉ«ÐÅÏ¢
sp_helpsrvrolemember
ÐÞ¸´Ç¨ÒÆ·þÎñÆ÷ʱ¹ÂÁ¢Óû§Ê±,¿ÉÒÔÓõÄfix_orphan_user½Å±¾»òÕßLoneUser¹ý³Ì
¸ü¸Äij¸öÊý¾Ý¶ÔÏóµÄÓû§ÊôÖ÷
sp_changeobjectowner [@objectname =] 'object', [@newowner =] 'owner'
×¢Òâ: ¸ü¸Ä¶ÔÏóÃûµÄÈÎÒ»²¿·Ö¶¼¿ÉÄÜÆÆ»µ½Å±¾ºÍ´æ´¢¹ý³Ì¡£
°Ñһ̨·þÎñÆ÷ÉϵÄÊý¾Ý¿âÓû§µÇ¼ÐÅÏ¢±¸·Ý³öÀ´¿ÉÒÔÓÃadd_login_to_aserver½Å±¾
7. ²é¿´Á´½Ó·þÎñÆ÷
sp_helplinkedsrvlogin
²é¿´Ô¶¶ËÊý¾Ý¿âÓû§µÇ¼ÐÅÏ¢
sp_helpremotelogin
8.²é¿´Ä³Êý¾Ý¿âÏÂij¸öÊý¾Ý¶ÔÏóµÄ´óС
sp_spaceused @objname
»¹¿ÉÒÔÓÃsp_toptables¹ý³Ì¿´×î´óµÄN(ĬÈÏΪ50)¸ö±í
²é¿´Ä³Êý¾Ý¿âÏÂij¸öÊý¾Ý¶ÔÏóµÄË÷ÒýÐÅÏ¢
sp_helpindex @objname
»¹¿ÉÒÔÓÃSP_NChelpindex¹ý³Ì²é¿´¸üÏêϸµÄË÷ÒýÇé¿ö
SP_NChelpindex @objname
clusteredË÷ÒýÊǰѼǼ°´ÎïÀí˳ÐòÅÅÁеģ¬Ë÷ÒýÕ¼µÄ¿Õ¼ä±È½ÏÉÙ¡£
¶Ô¼üÖµDML²Ù×÷Ê®·ÖƵ·±µÄ±íÎÒ½¨ÒéÓ÷ÇclusteredË÷ÒýºÍÔ¼Êø£¬fillfactor²ÎÊý¶¼ÓÃĬÈÏÖµ¡£
²é¿´Ä³Êý¾Ý¿âÏÂij¸öÊý¾Ý¶ÔÏóµÄµÄÔ¼ÊøÐÅÏ¢
sp_helpconstraint @objname
9.²é¿´Êý¾Ý¿âÀïËùÓеĴ洢¹ý³ÌºÍº¯Êý
use @database_name
sp_stored_procedures
²é¿´´æ´¢¹ý³ÌºÍº¯ÊýµÄÔ´´úÂë
sp_helptext '@
Ïà¹ØÎĵµ£º
×î½üÕûÀí³öÀ´µÄ.Èç¹û²»ÍêÈ«µÄ»°Ï£Íû´ó¼Ò²¹³ä.
ÔÚaccessÖУ¬×ª»»Îª´óдµÄsqlº¯ÊýÊÇucase£¬ÔÚsqlserverÖУ¬×ª»»Îª´óдµÄº¯ÊýÊÇupper£»ÔÚaccessÖУ¬×ª»»ÎªÐ¡Ð´µÄº¯ÊýÊÇlcase£¬ÔÚsqlserverÖУ¬×ª»»ÎªÐ¡Ð´µÄº¯ÊýÊÇlower£»ÔÚaccessÖУ¬È¡µ±Ç°Ê±¼äµÄº¯ÊýÊÇnow£¬ÁíÍ⻹ÓÐÒ»¸öÈ¡ÈÕÆÚº¯Êýdate£¬ÔÚsqlserverÖУ¬È¡µ±Ç°µÄº¯ÊýÊÇgetdate ......
SQL°æ±¾Éí·ÝÖ¤¸ñʽÑéÖ¤ 0Ϊ´íÎó£¬1ΪÕýÈ·
CREATE function [dbo].[IsID](@str nvarchar(18),@sex int)--´«ÈëÁ½¸ö±äÁ¿ Éí·ÝÖ¤ºÍÐÔ±ð(ÄÐ1Å®2)
returns bit
as
begin
declare @len int
declare @result bit
--set @result=0
set @len=len(@str)
if(@len!=18 and @len!=15)--³¤¶ÈÊÇ18λ»ò15λ
begin
& ......
SQLµÄÓÅ»¯Ó¦¸Ã´Ó5¸ö·½Ãæ½øÐе÷Õû£º
1.È¥µô²»±ØÒªµÄ´óÐͱíµÄÈ«±íɨÃè
2.»º´æСÐͱíµÄÈ«±íɨÃè
3.¼ìÑéÓÅ»¯Ë÷ÒýµÄʹÓÃ
4.¼ìÑéÓÅ»¯µÄÁ¬½Ó¼¼Êõ
5.¾¡¿ÉÄܼõÉÙÖ´Ðмƻ®µÄCost
SQLÓï¾ä£º
ÊǶÔÊý¾Ý¿â(Êý¾Ý)½øÐвÙ×÷µÄΩһ;¾¶£»
ÏûºÄÁË70%~90%µÄÊý¾Ý¿â×ÊÔ´£»¶ÀÁ¢ÓÚ³ÌÐòÉè¼ÆÂß¼£¬Ïà¶ÔÓÚ¶Ô³ÌÐòÔ´´úÂëµÄÓÅ»¯£¬¶ÔSQLÓï¾äµÄÓÅ» ......