¡¾SQL ServerÖÐSMOµÄ¼òµ¥Ê¹Óá¿
SMOÊÇSQL Mangagement ObjectsµÄ¼ò³Æ.ÓëÖ®Ïà¶ÔÓ¦µÄÊÇADO.Net¡£
²»¹ý²»Í¬µÄµØ·½ÊÇADO.NetÊÇÓÃÓÚÊý¾Ý·ÃÎʵÄ,¶øSMOÊÇÓÃÓÚÉè¼ÆµÄ,ËäÈ»SMOÄܹ»ÔÙ·þÎñÆ÷ÉÏÖ´ÐÐÈÎÒâµÄSQLÓï¾ä.
ÁíÍâÒ»¸ö²»Í¬µÄµØ·½ÊÇADO.Net¿ÉÒÔ·ÃÎʼÆËã»úÖÐÈÎÒâÊý¾ÝÔ´,¶øSMO¶ÔÏóÊÇרÃÅÕë¶ÔSQL Server¶øÉè¼ÆµÄ.
ÔÚSMOÖÐ×îÖØÒªµÄÒ»¸öÀà¾ÍÊÇServer.ÆäËû´ó¶àÊý¶ÔÏó¶¼ÊÇServer¶ÔÏóµÄºó´ú.±ÈÈçDatabase,Table,ViewµÈµÈ¶ÔÏó¶¼ÊÇͨ¹ýServerÊôÐÔ²»¶ÏÏòϼìË÷µ½µÄ.
ÒªÔÚVS2005/vs2008ÖÐʹÓñØÐëÒýÓÃSMOµÄ³ÌÐò¼¯.ÎÒÃǽ¨Á¢ºÃÒ»¸ö¿ØÖÆ̨ӦÓóÌÐò,Ìí¼ÓÒýÓÃ:Microsoft.SqlServer.ConnectionInfoºÍMicrosoft.SqlServer.Smo.
¸ü¶àÄÚÈÝ Çë²Î¿´ http://social.msdn.microsoft.com/Search/zh-cn?query=smo
ÕâÀïÓиö²åÇú£ºÎÒÔÚµÚÒ»´Î×öµÄʱºò³öÏÖ´íÎó£ºhttp://topic.csdn.net/u/20100515/19/c1298085-5d2e-41b4-8b91-7003b039aac0.html ½â¾ö·½·¨¼ûÄÚ
ÏÂÃæÊÇSMOµÄ»ù±¾²Ù×÷
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//½¨Á¢Êý¾Ý¿âʵÀýÁ¬½Ó
Server s = new Server("POOFLY-PC");
ServerConnection sc = s.ConnectionContext;
sc.LoginSecure = false;
sc.Login = "sa";
sc.Password = "123456";
sc.Connect();
//Êä³öÊý¾Ý¿âÊýÄ¿ºÍµÚÒ»¸öÊý¾Ý¿âÃû
Console.WriteLine("DatabaseCount:" + s.Databases.Count);
Console.WriteLine(s.Databases[0].Name);
//´´½¨Êý¾Ý¿â
Database db = new Database(s, "newdb");
db.Create();
//½¨±íTb
Table tb = new Table(db, "NewTableName");
Column c = new Column(tb, "CustomerID");
c.Identity = true;
c.IdentitySeed = 1;
c.DataType = DataType.Int;
c.Nullable = false;
tb.Columns.Add(c);
c = new Column(tb, "CustomerName");
Ïà¹ØÎĵµ£º
»ù±¾µÄSql±àдעÒâÊÂÏî
¾¡Á¿ÉÙÓÃIN²Ù×÷·û£¬»ù±¾ÉÏËùÓеÄIN²Ù×÷·û¶¼¿ÉÒÔÓÃEXISTS´úÌæ¡£
²»ÓÃNOT IN²Ù×÷·û£¬¿ÉÒÔÓÃNOT EXISTS»òÕßÍâÁ¬½Ó+Ìæ´ú¡£
OracleÔÚÖ´ÐÐIN×Ó²éѯʱ£¬Ê×ÏÈÖ´ÐÐ×Ó²éѯ£¬½«²éѯ½á¹û·ÅÈëÁÙʱ±íÔÙÖ´ÐÐÖ÷²éѯ¡£¶øEXISTÔòÊÇÊ×Ïȼì²éÖ÷²éѯ£¬È»ºóÔËÐÐ×Ó²éѯֱµ½ÕÒµ½
µÚÒ»¸öÆ¥ÅäÏî¡£NOT EXISTS±ÈNOT INЧÂÊÉ ......
ÔÚOracle SQLÖÐÈ¡Êý¾ÝʱÓÐʱҪÓõ½in ºÍ exists ÄÇôËûÃÇÓÐʲôÇø±ðÄØ£¿
1 ÐÔÄÜÉϵıȽÏ
±ÈÈçSelect * from T1 where x in ( select y from T2 )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
숦﵀
select * from t1 where exists ( select null fro ......
--
SQL Server£º
Select
TOP
N
*
from
TABLE
Order
By
NewID
()
--
Access£º
Select
TOP
N
*
from
TABLE
Order
By
Rnd(ID)
Rnd(ID) ÆäÖеÄID ......
declare @a int
set @a = 1
while @a<1000000
begin
insert into Test(name) values(@a)
set @a = @a + 1
end ......