Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : sql

·ÀÖ¹sql×¢Èë ÊÊÓÃÓÚ URL ID ´¿Êý×Ö

Àý×Ó£º  int id = Convert.ToInt32(replace((Request.QueryString["id"]), ""));
    public static string replace(string str, string str2)
    {
        str = str.Replace(";", str2);
        str = str.Replace("&", str2);
        str = str.Replace("<", str2);
        str = str.Replace(">", str2);
        str = str.Replace("'", str2);
        str = str.Replace("--", str2);
        str = str.Replace("/", str2);
        str = str.Replace("%", str2);
        str = str.Replace("~", str2);
        str = str.Replace(",", str2);
        str = str.Replace("`", str2) ......

bulletedlist ¼Ó sql server ²É¼¯ÍøÕ¾µØÖ·

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
    {//»ñÈ¡±»Ñ¡ÏîµÄÎı¾Öµ
        Response.Write(BulletedList3.Items[e.Index].Text);
    }
    protected void BulletedList2_DataBound(object sender, EventArgs e)
    {//×öÁ¬½Ó
        string[] val = new string[BulletedList2.Items.Count];
        for (int i = 0; i < BulletedList2.Items.Count; i++)
  &n ......

µ÷ÓÃSQLº¯ÊýÀ´ÊµÏÖºº×ÖÄ£ºý²éѯ

ÔÚsqlÖд´½¨Óû§×Ô¶¨Ò寴Òôº¯Êý£º
create function f_GetPy(@Str nvarchar(400))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert @t select 'ß¹','A' union all select '°Ë','B'
union all select 'àê','C' union all select '咑','D'
union all select '妸','E' union all select '·¢','F'
union all select 'ê¸','G' union all select 'îþ','H'
union all select 'Ø¢','J' union all select 'ßÇ','K'
union all select 'À¬','L' union all select '嘸','M'
union all select '拏','N' union all select 'àÞ','O'
union all select '妑','P' union all select 'Æß','Q'
union all select '呥','R' union all select 'Øí','S'
union all select 'Ëû','T' union all select '屲','W'
union all select 'Ϧ','X' union all select 'Ѿ','Y'
union all select '帀','Z'
select @strlen=len(@str),@re=''
while @strlen>0
begin
select top 1 @re=letter+@re,@strlen=@strlen-1
from @t ......

SQL²Ù×÷È«¼¯

ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack
4¡¢ËµÃ÷£º´´½¨Ð±í
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
¸ù¾ÝÒÑÓÐµÄ±í´´½¨ÐÂ±í£º
A£ºcreate table tab_new like tab_old (ʹÓÃ¾É±í´´½¨Ð±í)
B£ºcreate table tab_new as select col1,col2… from tab_old definition only
5¡¢ËµÃ÷£ºÉ¾³ýбídrop table tabname
6¡¢ËµÃ÷£ºÔö¼ÓÒ»¸öÁÐ
Alter table tabname add column col type
×¢£ºÁÐÔö¼Óºó½«²»ÄÜɾ³ý¡£DB2ÖÐÁмÓÉϺóÊý¾ÝÀàÐÍÒ²²»Äܸı䣬ΨһÄܸıäµÄÊÇÔö¼Óv ......

ADO.NETÓëORMµÄ±È½Ï(3):Linq to SQLʵÏÖCRUD

  ËµÃ÷£º¸öÈ˸оõÔÚJavaÁìÓò´óÐÍ¿ª·¢¶¼Àë²»ÁËORMµÄÉíÓ°£¬ËùνµÄSSH¾ÍÊÇSpring+Struts+Hibernate£¬³ýÁËÔÚѧϰ»ù´¡ÖªÊ¶µÄʱºò±»¸æÖª¿ÉÒÔʹÓÃJDBC²Ù×÷Êý¾Ý¿âÖ®Í⣬´óÁ¿µÄÊé¼®Öж¼Êǽ²ÊöʹÓÃHibernateÕâ¸öORM¹¤¾ßÀ´²Ù×÷Êý¾Ý¡£ÔÚ.NETÖвÙ×÷Êý¾Ý¿âµÄ·½Ê½ÓжàÖÖ£¬³ýÁË×îÖ±½ÓµÄ·½Ê½¾ÍÊÇʹÓÃADO.NETÖ®Í⣬»¹¿ÉÒÔʹÓÃNHibernateÕâ¸öHibernateÔÚ.NETÖеÄʵÏÖORM£¬Èç¹ûÄã¶ÔµÚÈý·½µÄORM³Ö»³ÒÉ̬¶È£¬Ä㻹¿ÉÒÔʹÓÃÀ´×Ô΢ÈíµÄʵÏÖ¡¢¸ùÕýÃçºìµÄLinq»òÕßEntityFramework¡£
 ´ó²¿·Ö´ÓÔçÆÚ¾Í¿ªÊ¼Ê¹ÓÃ.NET¿ª·¢µÄ³ÌÐòÔ±¿ÉÄܶÔADO.NETÓÐÖÖÃÔÁµ£¬Ê¹ÓÃADO.NET¿ÉÒÔ³ä·Ö½«ÎÒÃÇÔçÆÚµÄSQL֪ʶ·¢»ÓµÃÁÜÀ쾡Ö£¬²¢ÇÒ³öÓÚ¶ÔÐÔÄܵĿ¼ÂÇ£¬ÓÐЩÈ˶Ô.NETÖеÄORM»¹±£³ÖÒ»ÖÖ¹ÛÍû̬¶È£¬°üÀ¨ÎÒ×Ô¼ºÒ²ÊÇÕâÖÖ̬¶È¡£²»¹ý¼´Ê¹ÔÚʵ¼Ê¿ª·¢Öв»Ó㬲¢²»´ú±íÎÒÃDz»ÄÜÈ¥Á˽âºÍ±È½ÏÕâЩ¼¼Êõ£¬ÈκÎÊÂÎïµÄ³öÏÖºÍÏûÍö×ÜÓÐÆäÔ­ÒòµÄ£¬ÎÒÃÇ¿ÉÒÔÁ˽âËüÃǵÄÓŵãºÍ³¤´¦¡£ËùÒÔ±¾È˳é³öÁ˼¸¸öÖÜÄ©µÄʱ¼ä·Ö±ðÓÃADO.NET¡¢NHibernate¡¢LinqºÍEntityFrameworkÀ´ÊµÏÖ¶ÔÊý¾Ý¿âµ¥±íÊý¾ÝµÄ´´½¨¡¢¶ÁÈ¡¡¢¸üкÍɾ³ý²Ù×÷£¬Ò²¾ÍÊÇËùνµÄCRUD£¨C:Create/R:Read/U:Update/D:Delete£©¡£
 Í¨¹ýʵÏÖÏàͬ¹¦ÄܵıȽϣ¬´ó¼Ò×Ô¼ºÅжÏÄÇÖÖ·½Ê ......

SQL ServerºÍMySQLÖÐTopÓ÷¨µÄÇø±ð

      ½ñÌìÁ·Ï°ÔÚJSPÒ³ÃæÖÐʵÏÖ·ÖҳЧ¹û£¬ÔÚ²éѯÓï¾ä·½ÃæÇ£³¶µ½ÁËtopµÄÓ÷¨¡£¼òÒª×öÒ»ÏÂ×ܽ᣺
      ΪʵÏÖÀàËÆtopµÄ¹¦ÄÜ£¬ÎÒÃÇÔÚSQL ServerÖкÍMySQLÖÐʹÓõ½µÄSQLÓï¾äÊDz»Í¬µÄ¡£
      1¡¢ÔÚSQL ServerÖУ¬ÎÒÃÇʹÓà select top N * from tablenameÀ´²éѯtablename±íÖÐǰNÌõ¼Ç¼¡£
      2¡¢ÔÚMySQLÖУ¬ÎÒÃÇÔòʹÓÃselect * from tablename limit M,N À´ÊµÏÖÏàËÆµÄЧ¹û£¬ÆäÖÐM±íʾ´ÓµÚM+1Ìõ¼Ç¼¿ªÊ¼£¬N±íʾ·µ»ØNÌõ¼Ç¼¡£
      ÀýÈ磺´Óuses±íÖÐÈ¡³öµÚËÄÌõµ½µÚÁùÌõÕâÈýÌõ¼Ç¼£¬ÎÒÃǾͿÉÒÔÕâÑùд£º
¡¡¡¡¡¡¡¡1¡¢select top 3 * from users where userID not in(select top 3 userID from users)
¡¡¡¡¡¡¡¡2¡¢select * from users limit 3,3
      ......

SQL ServerºÍMySQLÖÐTopÓ÷¨µÄÇø±ð

      ½ñÌìÁ·Ï°ÔÚJSPÒ³ÃæÖÐʵÏÖ·ÖҳЧ¹û£¬ÔÚ²éѯÓï¾ä·½ÃæÇ£³¶µ½ÁËtopµÄÓ÷¨¡£¼òÒª×öÒ»ÏÂ×ܽ᣺
      ΪʵÏÖÀàËÆtopµÄ¹¦ÄÜ£¬ÎÒÃÇÔÚSQL ServerÖкÍMySQLÖÐʹÓõ½µÄSQLÓï¾äÊDz»Í¬µÄ¡£
      1¡¢ÔÚSQL ServerÖУ¬ÎÒÃÇʹÓà select top N * from tablenameÀ´²éѯtablename±íÖÐǰNÌõ¼Ç¼¡£
      2¡¢ÔÚMySQLÖУ¬ÎÒÃÇÔòʹÓÃselect * from tablename limit M,N À´ÊµÏÖÏàËÆµÄЧ¹û£¬ÆäÖÐM±íʾ´ÓµÚM+1Ìõ¼Ç¼¿ªÊ¼£¬N±íʾ·µ»ØNÌõ¼Ç¼¡£
      ÀýÈ磺´Óuses±íÖÐÈ¡³öµÚËÄÌõµ½µÚÁùÌõÕâÈýÌõ¼Ç¼£¬ÎÒÃǾͿÉÒÔÕâÑùд£º
¡¡¡¡¡¡¡¡1¡¢select top 3 * from users where userID not in(select top 3 userID from users)
¡¡¡¡¡¡¡¡2¡¢select * from users limit 3,3
      ......
×ܼǼÊý:4346; ×ÜÒ³Êý:725; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [206] [207] [208] [209] 210 [211] [212] [213] [214] [215]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ