Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ×¢È붶´Ïà¹Ø֪ʶÕûÀí

 ÉÏÉϸöÐÇÆÚ£¬ÓÐÈË·´À¡£¬CSDNÓÐSQL×¢È붶´£¬º¹ÑÕ£¬¼¸ÄêǰΪSQL×¢È붶´£¬²¿ÃÅרÃŶÔËùÓдúÂë×ö¹ýÒ»´Î·Ç³£´óµÄ¼ì²é£¬¾¹È»ÄǴμì²é»¹ÓÐÒÅ©µÄµØ·½¡£×î½üÕ⼸¸öÐÇÆÚ£¬¾ÍÊÇÒ»Ö±ÔÙ¶Ô´úÂë×öÔٴθ´²é£¬¿´ÓÐûÓÐSQL×¢È붶´¡£
        ´æÔÚSQL×¢È붶´£¬¾ÍÒòΪÄãµÄSQLÓï¾äÊÇ×Ô¼ºÆ´´ÕµÄ£¬ÔÚÆ´´ÕµÄʱºò£¬Ã»Óп¼ÂÇÓû§¿ÉÄÜÆ´´Õ½øÓÐÎÊÌâµÄÓï¾äÔì³ÉµÄ¡£
        Ö®Ç°ÎÒÃDzÉÈ¥µÄ±ÜÃâ´ëÊ©ÊÇ£¬¶Ô½ÓÊܵIJÎÊýµÄУÑé½øÐзâ×°£¬ËùÓвÎÊýµÄ»ñµÃ£¬¶¼±ØÐëͨ¹ýÕâ¸ö·â×°µÄº¯ÊýÀ´»ñµÃ¡£µ«ÊÇʵ¼Ê¿ª·¢ÖУ¬×ÜÓÐЩµØ·½£¬ÓÐЩ´úÂëûÓе÷ÓÃÕâ¸ö·â×°µÄº¯ÊýÀ´½øÐÐУÑé¡£
        ÉÏÖÜÄ©£¬¹«Ë¾ÄÚ²¿ÌÖÂÛ»áµÄʱºò£¬¾ö¶¨»»ÖÖ˼·¡£´Ó±ÜÃâ×Ô¼ºÆ´´ÕSQLÓï¾äµÄ·½Ê½À´ÊµÏÖ£¬¾ßÌå¾ÍÊÇ¿ª·¢¹æ·¶ÖÐÓÐÒ»Ìõ£¬²»ÔÊÐíÓÃÆ´´ÕµÄSQLÓï¾ä£¬Òª´«²ÎÊý£¬¾ÍÓÃSqlParameter¡£±ÈÈçÏÂÃæµÄ´úÂëÊDz»ÔÊÐíµÄ¡£
string strSQL = "select UserID,UserName,Email from User where UserName = '"+aa.replace("'","''")+"'";
SqlDataReader sdr = SqlHelper.ExecuteReader(strConnStr,CommandType.Text,strSQL)
¶øÏÂÃæµÄ´úÂëÊÇÔÊÐíµÄ£º
SqlParameter[] parm1 = new SqlParameter[]{
 new SqlParameter("@UserName",SqlDbType.NVarChar,50)
 };
parm1[0].Value = strUserName;
string strSQL = "select UserID,UserName,Email from user where UserName = @UserName ";
SqlDataReader sdr = SqlHelper.ExecuteReader(strConnStr,CommandType.Text,strSQL,parm1)
Ô­Òò£ºSqlParameter »á×Ô¶¯´¦Àí²ÎÊýµÄУÑ飬¾ÍÀàËÆʹÓô洢¹ý³ÌÊDz»»á³öÏÖSQL×¢È붶´µÄÎÊÌâÒ»Ñù¡£
һЩSQL×¢ÈëÓйصÄ֪ʶµã£º
ÈçºÎSQL×¢È룺
http://www.54nb.com/Read.Asp?ID=1451672&Type=71
SQL×¢ÈëÖÐÓÐÓõļ¸¸öSQLÓï¾ä
[N] = µÚN個±í
ID=1 and (Select top 1 name from(Select top [N] id,name from sysobjects where xtype=char(85)) T order by id desc)>1
[T] = ±íÃû
[N] = µÚN個×Ö¶Î
ID=1 and (Select Top 1 col_name(object_id('[T]'),[N]) from sysobjects)>1
SQL×¢Èë±íÃûºÍ×Ö¶ÎÃûµÄ»ñµÃ


Ïà¹ØÎĵµ£º

SQLSERVER SQLÐÔÄÜÓÅ»¯

1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......

SQL·ÖÒ³²éѯ

/*µÚ¼¸Ò³±ØÐë´óÓÚ1
select top ÿҳÊýÁ¿ * id
 from @t a
 where id not in
 (select top (µÚ¼¸Ò³-1)*ÿҳÊýÁ¿ id
  from @t b
 )
*/
declare @lcSqlCommand nvarchar(100)
declare @t table (id int IDENTITY,orderDate datetime)
insert into @t
 select orderDate
&nb ......

SQL select

--desc ±íÃû ÃèÊö±íµÄÄÚÈÝ  
desc emp;
--¼ÓÉÏÊýѧ±í´ïʽºÍÁÐÃû  ""±£³Ö¸ñʽ
select ename "name space", sal*12 year_sal from emp;   
select 2*3 from dual;
select sysdate from dual;
--¿ÕÖµµÄÊýѧ±í´ïʽ ½á¹û¶¼ÊÇ¿ÕÖµ
select ename, sal*12 + comm from emp;  
- ......

sqlÓï¾ä»ù´¡

--sql structured query language
--DML--Data Manipulation Language--Êý¾Ý²Ù×÷ÓïÑÔ
query information (SELECT),
add new rows (INSERT),
modify existing rows (UPDATE),
delete existing rows (DELETE),
perform a conditional update or insert operation (MERGE),
see an execution plan of SQL (EXPLA ......

sqlѧϰ½øÐÐʱ

ÕâÁ½Ì춼ûÓкúÃѧϰ£¬½ñÌìÖÕÓÚËãͶÈëÁËЩ£¬ÓÉÓڿγ̵ĹØϵ£¬ÎÒµÄsqlÒ²ÊÇͬvbÒ»ÆðѧϰµÄ¡£ËäȻ֪µÀÌ°¶à½À²»À㬿ÉÊÇ°´ÕÕʵ¼ÊÇé¿ö£¬ÎÒÍêȫûÓÐÀíÓÉÅ×ÆúsqlµÄ¡£
×î½ü¶¼°Ñʱ¼äͶÈëµ½vbºÍÃæÏò¶ÔÏóÖУ¬sql½ñÌìºÃºÃ¸´Ï°ÁËÏ£¬´Ócreate database ¿ªÊ¼£¬create table£¬alter table £¬ add constraint   …&h ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ