Ô¤·ÀSQL×¢Èë¹¥»÷Ö®ÎÒ¼û
1¡¢ SQL×¢Èë¹¥»÷µÄ±¾ÖÊ£ºÈÿͻ§¶Ë´«µÝ¹ýÈ¥µÄ×Ö·û´®±ä³ÉSQLÓï¾ä£¬¶øÇÒÄܹ»±»Ö´ÐС£
2¡¢ ÿ¸ö³ÌÐòÔ±¶¼±ØÐë¼ç¸ºÆð·ÀÖ¹SQL×¢Èë¹¥»÷µÄÔðÈΡ£
¡¡¡¡ËµÆð·ÀÖ¹SQL×¢Èë¹¥»÷£¬¸Ð¾õºÜÓôÃÆ£¬Õâô¶àÄêÁË´ó¼ÒÒ»Ö±ÔÚÌÖÂÛ£¬Ò²Ò»Ö±ÔÚÕùÂÛ£¬¿ÉÊǵ½ÁËÏÖÔÚËƺõ»¹ÊÇûÓж¨ÂÛ¡£µ±²»ÖªµÀ×¢ÈëÔÀíµÄʱºò»á¾õµÃºÜÉñÆ棬Ôõô¾Í±»×¢ÈëÁËÄØ£¿»á¾õµÃºÜÄÑÔ¤·À¡£µ«Êǵ±ÖªµÀÁË×¢ÈëÔÀíÖ®ºóÔ¤·À²»¾ÍÊǺܼòµ¥µÄÊÂÇéÁËÂð£¿
¡¡¡¡µÚÒ»´ÎÌý˵SQL×¢Èë¹¥»÷µÄʱºò»¹ÊÇÔÚ2004Ä꣨ºÃÏñµÃÖªµÄ±È½ÏÍí£©£¬ÄÇÊÇ»¹ÊÇÔÚдaspÄØ¡£ÔÚÒ»´Îд´úÂëµÄʱºò£¬ÓÐͬÊÂÎÊÎÒ£¬ÄãµÄÕâ¶Î´úÂë·À×¢Èë¹¥»÷ÁËÂð£¿Ê²Ã´¹¥»÷£¿ÕâÊÇʲôѽ¡£
¡¡¡¡ºóÀ´µ½ÍøÉϸ÷ÖÖÕÒ£¬ÖÕÓÚŪÃ÷°×ÁËÊÇÔõô¹¥»÷½øÀ´µÄÁË¡£×¢Èë¹¥»÷¶¼ÊÇÀ´×ÔÓÚ¿Í»§¶Ë£¬ÎÞÂÛÊÇ±íµ¥Ìá½»¡¢URL´«Öµ»¹ÊÇCookieµÈ£¬ÆäʵÔÀí¶¼ÊÇÒ»ÑùµÄ¡£µ½ÁË·þÎñÆ÷¶Ë¿ÉÒÔ·Ö³ÉÈýÖÖÇé¿ö£ºÊý×Ö¡¢ÈÕÆÚʱ¼ä¡¢×Ö·û´®¡£
Ò»¡¢Êý×Ö¡£
¡¡¡¡ÈçºÎ×¢È룿
¡¡¡¡¼ÙÉèÎÒÃÇҪʵÏÖÒ»¸öÏÔʾÐÂÎŵÄÒ³Ã棬ÎÒÃÇ¿ÉÄÜ»áËæÊÖдÏÂÏÂÃæµÄ´úÂ룺
string id = Request.QueryString["id"];
string sql = "select * from news where ColID=" + id;
¡¡¡¡Èç¹û´«µÝ¹ýÀ´µÄ idÊÇÎÒÃÇÏëÏñµÄ Êý×Ö£¨±ÈÈç168£©£¬ÄÇô×ÔÈ»²»»áÓÐʲôÎÊÌâ¡£µ«ÊÇÈç¹û´«µÝ¹ýÀ´µÄidÊÇ“168 delete from table ”µÄ»°£¬ÄÇôsqlµÄÖµ¾Í±ä³ÉÁË“select * from table where ColID=168 delete from news”¡£¶ÔÓÚSQL ServerÀ´ËµÊÇÖ§³ÖÒ»´ÎÌá½»¶àÌõSQLÓï¾äµÄ£¬Õâ¸öΪÎÒÃÇÌṩÁË·½±ãÖ®ÓàҲΪSQL×¢È볨¿ªÁË´óÃÅ¡£ÏÔÈ»Èç¹ûÕâÌõSQLÓï¾ä±»Ö´ÐеĻ°£¬ÄÇônews±íÀïµÄ¼Ç¼¾Í¶¼Ã»ÓÐÁË¡£
¡¡ÄÇôÈçºÎÔ¤·ÀÄØ£¿ºÜ¼òµ¥£¬ÒòΪColID×ֶεÄÀàÐÍÊÇintµÄ£¬ÄÇôÎÒÃÇÖ»ÐèÒªÑé֤һϴ«µÝ¹ýÀ´µÄidÊDz»ÊÇÕûÊý¾Í¿ÉÒÔÁË¡£ÊÇÕûÊý¾Í²»´æÔÚ×¢È룻Èç¹û²»ÊÇÄÇô¾ÍÓпÉÄÜ´æÔÚ×¢Èë¡£¼´Ê¹²»´æÔÚ×¢È룬°ÑÒ»¸ö²»ÊÇÕûÊýµÄidÆ´½Ó½øÈ¥Ò²»áÔì³ÉÖ´ÐдíÎó¡£
¡¡¡¡ËùÒÔ˵²»¹ÜÊDz»ÊÇΪÁËÔ¤·ÀSQL×¢È룬Ҳ¶¼Ó¦¸ÃÑéÖ¤idÊDz»ÊÇÕûÊý¡£¡¡¡¡
¡¡¡¡ÑéÖ¤·½·¨Â¿ÉÒÔÓÃTryParse£¬¿ÉÒÔÓÃÕýÔò£¬Ò²¿ÉÒÔ×Ô¼ºÐ´º¯ÊýÑéÖ¤¡£µ«ÊDz»½¨ÒéÓÃtryÒì³£µÄ·½Ê½£¬ÒòΪÕâ¸öÓÐЧÂÊÎÊÌâ¡£
¡¡¡¡ÕâÀﻹÓÐÒ»¸öÌØÊâÇé¿ö£¬¾ÍÊǶÔÓÚÅúÁ¿É¾³ýÕâÀàµÄ»á´«µÝ¹ýÀ´¶à¸öÊý×Ö£¬±ÈÈç“1£¬2£¬3£¬10”£¬Õâ¸öÒ²ÐèÒªÑé֤һϣ¬ÍòÒ»ÓÐÈËÀûÓÃÕâ¸ö©¶´ÄØ¡£ÖÁÓÚÑéÖ¤·½·¨Ò²ºÜ¼òµ¥£¬×Ô¼ºÐ´¸öº¯Êý¾ÍokÁË¡£
¶þ¡¢ÈÕÆÚʱ¼ä
¡¡¡¡Õâ¸öºÍÊý×ÖµÄÇé¿öÊÇÒ»
Ïà¹ØÎĵµ£º
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
µ÷ÓÃSQL´æ´¢¹ý³Ì ´æ´¢¹ý³ÌÔÚÒ»¸öµ¥ÔªÖзâ×°Á˸´ÔÓµÄSQL²éѯºÍÊý¾Ý¹ý³Ì£¬¿ÉÒÔÓɶà¸ö³ÌÐò»òÓû§Ö®¼äµ÷Óá£
Àý£º
......
sql DATEPARTº¯ÊýʹÓÃ(Õª³)
sql DATEPARTº¯ÊýʹÓÃ
DATEPART
·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
Óï·¨
DATEPART ( datepart ,date )
²ÎÊý
datepart
ÊÇÖ¸¶¨Ó¦·µ»ØµÄÈÕÆÚ²¿·ÖµÄ²ÎÊý¡£Ï±íÁгöÁË Microsoft® SQL Server™ ʶ±ðµÄÈÕÆÚ²¿·ÖºÍËõд¡£
ÈÕÆÚ²¿·ÖËõд
year
yy, yyyy
quarter
qq, q
mont ......
Sql server2005ÓÅ»¯²éѯËÙ¶È51·¨²éѯËÙ¶ÈÂýµÄÔÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ£¬´ó¼Ò¿ÉÒԲο¼Ï¡£
I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
¡¡¡¡Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
¡¡¡¡ÄÚ´æ²»×ã¡£
¡¡¡¡ÍøÂçËÙ¶ÈÂý¡£
¡¡¡¡²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)¡£
¡¡¡¡Ëø»òÕßËÀËø(ÕâÒ²ÊDzéѯÂý×î³£¼ûµÄÎÊÌ ......
Êýѧº¯Êý
1.¾ø¶ÔÖµ
S:select abs(-1) value
O:select abs(-1) value from dual
2.È¡Õû(´ó)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.È¡Õû£¨Ð¡£©
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.È¡Õû£¨½ØÈ¡£©
S:select cast(-1.002 as in ......
Sample1:
/* Variable Declaration */
DECLARE @EmpID AS SMALLINT
DECLARE @SQLQuery AS NVARCHAR(500)
/* Build and Execute a Transact-SQL String with a single parameter value Using EXECUTE Command */
SET @EmpID = 1001
SET @SQLQuery = 'SELECT * from tblEmployees WHERE EmployeeID = ' + CAST(@EmpID A ......