PowerShell±Ê¼Ç£¨Èý£©£ºµ÷ÓÃMS SQLÊý¾Ý¿â
ÊÔÁËÒ»°ÑPowerShell·ÃÎÊÊý¾Ý¿â£¬¸úÓÃC#д¼¸ºõûÈκÎÇø±ð~
ΪÁ˼òµ¥Æð¼û£¬´úÂëÓеã³ó£¬²»ÓÃÌ«É
$ConnString = "server=_SERVER_;database=_DATABASE_;user id=_UID_;password=_PWD_";
$db = New-Object System.Data.SqlClient.SqlConnection($ConnString);
$db.Open();
$Sql = "select top 10 * from sys.objects where type='U' order by [Name]";
$cmd = New-Object System.Data.SqlClient.SqlCommand($Sql,$db);
$r = $cmd.ExecuteReader();
$a = "","";
while ($r.Read())
{
$a = $a + $r["Name"].ToString();
}
$r.Close();
$cmd.Dispose();
$db.Close();
$db.Dispose();
echo $a
Ïà¹ØÎĵµ£º
×î½üѧSQL Server2005£¬ÏÂÔØÁËSQL2005ÖÐÎÄ¿ª·¢°æ£¬µ«ÊÇͬѧÃǶ¼°²×°ÉÏÁË£¬Î¨¶ÀÎҵĻúÆ÷°²×°²»ÉÏ¡£
ÿ´Î°²×°DATABASEµÄʱºò¶¼ÌáʾÎÞ·¨Æô¶¯sqlservr.exe·þÎñÎÞ·¨Æô¶¯£¬ÖØ×°ÏµÍ³Ò²²»ÐУ¬WINXP WIN 7ÏÂÃæ¶¼ÎÞ·¨°²×°£¬ÓÚÊÇÉÏÍø²éÁËÏ£¬ÔÀ´SQL2005²»Ö§³Ö3ºË´¦ÀíÆ÷£¬Î¢ÈíÒ²×Ô ......
ÔÚÐ¶ÔØVisual Studio 2008 ʱ£¬Ìí¼Ó/ɾ³ý³ÌÐò ÀïÃæÓÐÐí¶àµÄ°²×°Îļþ£¬´ËʱÈç¹ûûÓÐÏÈÐ¶ÔØSQL Server 2005 £¬
¶øÏÈÐ¶ÔØ.Net Framework£¨Ìáʾ£ºÐ¶ÔØ.net FrameworkµÄµÃ°²°æ±¾´Ó¸ßµ½µÍµÄ˳Ðò£©£¬
ÕâʱSQL Server 2005¾ÍÎÞ·¨Ð¶ÔØ,ɾ³ýProgram files ÏÂÃæµÄ Microsoft SQL Server Îļþ¼ÐҲûÓÐ×÷Óá£
ÖØÐ°²×°ÌáʾÊý¾Ý¿ ......
¡¾Ñ§Ï°µãµãµÎµÎ¡¿ ÔںܶàÇé¿öÓë»·¾³ÖУ¬ÎÒÃǶ¼Òª¶ÔÒÑÓеÄÊý¾Ý¿â½øÐб¸·Ý£¬ÕâÑùÒÔ·ÀÖ¹µ±ÎÒÃÇÒòÈËΪ»òÕß·þÎñÆ÷µÈÖî¶àÔÒò¶øµ¼ÖµÄÊý¾Ý¶ªÊ§£¬
´Ó¶ø¸øÎÒÃÇ´øÀ´ºÜ´óµÄÂé·³£¬ÎÒÒ²ÊǽӴ¥SQLû¶à³¤Ê±¼ä£¬¶ÔÓëËüÇ¿´óµÄÊý¾Ý¿É»Ö¸´¹¦ÄÜ Ò²Ö»ÊÇÂÔÖªÒ»¶þ£¬µ±È»ÔÚÕâÀïÒ²Ö»ÊÇ×ö¶ÔËü×öÂÔÂԵļǼ£¬
´¿´âÊÇ ......
ÔÚÕâÒ»Ò³ÖУ¬ÎÒÃÇÁгöËùÓÐÔÚÕâ¸öÍøÕ¾ÓÐÁгö SQL Ö¸ÁîµÄÓï·¨¡£ÈôÒª¸üÏ꾡µÄ˵Ã÷£¬ÇëµãѡָÁîÃû³Æ¡£
ÕâÒ»Ò³µÄÄ¿µÄÊÇÌṩһ¸ö¼ò½àµÄ SQL Óï·¨×öΪ¶ÁÕ߲ο¼Ö®Óá£ÎÒÃǽ¨ÒéÄúÏÖÔھͰ´ Control-D ½«±¾Ò³¼ÓÈëÄúµÄ¡ºÎÒµÄ×î°®¡»¡£
Select
SELECT "À¸Î»" from "±í¸ñÃû"
Distinct
SELECT DISTINCT "À¸Î»"
from "±í¸ñÃû"
Where
......
·Ï»°ÉÙ˵,(ÒѾÓоä·Ï»°ÁË.)
¿´±í
Óï¾ä: SELECT * from C
//---------------------------------------
Cno Cname Teacher
---- ---------- --------
1 ÓïÎÄ Æî¾²
2 &n ......