ÈçºÎÓÐЧµÄ·ÀÖ¹SQLÁ¬½Ó×Ö·û´®×¢Èë
¸ÅÄÔÚ±àд°²È«´úÂëʱ£¬×îÖØÒªµÄ¹æÔòÖ®Ò»¾ÍÊÇ“¾ø¶Ô²»ÒªÃ¤Ä¿µÄÏàÐÅÓû§µÄÊäÈ딡£
ÀûÓÃADO.NET 2.0µÄSqlConnectionStringBuilderÀàÉú³ÉÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬Ëü¿ÉÒÔÓÐЧµÄ·ÀÖ¹“SQLÁ¬½Ó×Ö·û´®¶ñÒâ×¢È딣¬ÒòΪÕâ¸öÀàÊÇרÃÅΪSQL SERVERÉè¼ÆµÄËùÒÔ£»Ëü¼æÈݾÉʽ¹Ø¼ü×Ö¡£¹ØÓÚÈçºÎʹÓÃSqlConnectionStringBuilderÀ࣬Çë²Î¿¼ÎÒÒÔǰдµÄһƪ“ÖÇÄÜÊý¾Ý¿âÁ¬½ÓÉú³ÉÆ÷”ÎÄÕÂÀï¡£
·ÀÖ¹SQLÊý¾Ý¿âÁ¬½Ó×Ö·û´®Ê¾Àý
C#ºǫ́ʾÀý´úÂ룺
SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
bldr.DataSource = @".\SQLExpress";
bldr.InitialCatalog = "Pubs";
bldr.UserID = textBox1.Text;
bldr.Password = textBox2.Text;
¸Õ²Å¿´µ½Ç°Ì¨Óû§ÔÚÓû§ÃûÊäÈëµÄÓû§Ãû×Ö·û´®£¬¾ÍÊǶñÒâSQL×¢È룬¶øSqlConnectionStringBuilder»á°Ñ
“Óû§Ãû£»Data Source=Northwind”µÄ×Ö·û´®×÷Ϊ“UesrID”À´µÇ¼Êý¾Ý¿â¡£Õâ¾Í·ÀÖ¹¶ñÒâµÄ×¢ÈëÁË¡£
×îºóÏ£ÍûÄܺÍ־ͬµÀºÏµÄ¿ª·¢Í¬Ö¾£¬Ò»Æðѧϰ£¬Ò»Æð·ÖÏí¡£Ð»Ð»
ÍƼöÁ´½Ó:»ÝÆÕºÚ°×¼¤¹â´òÓ¡»ú/°®ÆÕÉúÕëʽ´òÓ¡»ú
Ïà¹ØÎĵµ£º
getdate //»ñµÃϵͳµ±Ç°ÈÕÆÚ
datepart //»ñÈ¡ÈÕÆÚÖ¸¶¨²¿·Ö£¨ÄêÔÂÈÕʱ·Ö±í£©
getdate()º¯Êý£ºÈ¡µÃϵͳµ±Ç°µÄÈÕÆÚºÍʱ¼ä¡£·µ»ØֵΪdatetimeÀàÐ͵ġ£
Ó÷¨£ºgetdate()
Àý×Ó£º
select getdate() as dte,dateadd(day,-1,getdate()) as nowdat
Êä³ö½á¹û£º
dte nowdat
--------------------------- ----------------- ......
×ö¿ª·¢µÄ¹ý³ÌÖо³£Óõ½Êý¾Ý¿âÔ¶³ÌÁ¬½ÓµÄÎÊÌ⣬ÓÐʱºòŪÁË°ëÌìÒ²½â¾ö²»ÁË£¬ÕâÀï¸ù¾ÝÎÒ×Ô¼ºµÄÒ»µã¾Àú¶ÔSQL ServerÔ¶³ÌÁ¬½ÓÎÊÌâ×öÒ»×ܼơ£
Ê×ÏÈÕâÀïÖ÷Ҫ˵µÄÊÇSQL Server 2005²»ÊÇ2000£¬ÒòΪ2000ÓÐһЩСµÄÀýÍ⣬ÀýÈç°²×°sp4²¹¶¡µÈ£¬ÕâÀï²»ÔÙÌÖÂÛ¡£ÊÂʵÉÏÎÒ ......
SqlÓï¾ä
1. ˵Ã÷£º¸´ÖƱí(Ö»¸´Öƽṹ£¬Ô´±íÃû£ºa£¬Ð±íÃû£ºb) SQL:select * into bfrom awhere 1<>1;
2. ˵Ã÷£º¿½±´± ......
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GETDATE(), 4): 16.05.06
Select CONVERT ......