C# SQLÊý¾Ý¿â²Ù×÷ͨÓÃÀà
C# SQLÊý¾Ý¿â²Ù×÷ͨÓÃÀà
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace Framework.DataBase
{
///
/// ͨÓÃÊý¾Ý¿âÀà
///
public class DataBase
{
private string ConnStr = null;
public DataBase()
{
ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
}
public DataBase(string Str)
{
try
{
this.ConnStr = Str;
}
catch(Exception ex)
{
throw ex;
}
}
///
/// ·µ»Øconnection¶ÔÏó
///
///
public SqlConnection ReturnConn()
{
SqlConnection Conn = new SqlConnection(ConnStr);
Conn.Open();
return Conn;
}
public void Dispose(SqlConnection Conn)
{
if(Conn!=null)
{
Conn.Close();
Conn.Dispose();
}
}
///
/// ÔËÐÐSQLÓï¾ä
///
///
public void RunProc(string SQL)
{
SqlConnection Conn;
Conn = new SqlConnection(ConnStr);
Conn.Open();
SqlCommand Cmd ;
Cmd = CreateCmd(SQL, Conn);
try
{
Cmd.ExecuteNonQuery();
}
catch
{
throw new Exception(SQL);
}
Dispose(Conn);
return;
}
///
/// ÔËÐÐSQLÓï¾ä·µ»ØDataReader
///
///
/// SqlDataReader¶ÔÏó.
public SqlDataReader RunProcGetReader(string SQL)
{
SqlConnection Conn;
Conn = new SqlConnection(ConnStr);
Conn.Open();
SqlCommand Cmd ;
Cmd = CreateCmd(SQL, Conn);
SqlDataReader Dr;
try
{
Dr = Cmd.ExecuteReader(CommandBehavior.Default);
}
catch
Ïà¹ØÎĵµ£º
ÔÚSQLÓï¾äÓÅ»¯¹ý³ÌÖУ¬ÎÒÃǾ³£»áÓõ½hint,ÏÖ×ܽáÒ»ÏÂÔÚSQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨£º
1. /*+ALL_ROWS*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÍÌÍÂÁ¿,ʹ×ÊÔ´ÏûºÄ×îС»¯.
ÀýÈç:
SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
2. /*+FIRST_ROWS*/
±í ......
ÎÄÕÂÔ´´£¬×ªÔØÇëÓëBlogÖ÷ÈËÁªÏµ£¬robin9257@hotmail.com
JAVAÓëSQLÇŽӵÄÓÅȱµã£º
1¡¢Óŵ㣺²»ÓÃÏÂÔØÇý¶¯³ÌÐò£¬ÔÊÐíÓÃÏàͬ´úÂë·ÃÎʲ»Í¬DBMS¡£
2¡¢È±µã£ºÐ§Âʵ͡£
¾³£³öÏֵı¨´íµã£º
1¡¢java.sql.SQLException: [Microsoft][ODBC Çý¶¯³ÌÐò¹ÜÀíÆ÷] δ·¢ÏÖÊý¾ÝÔ´Ãû³Æ²¢ÇÒδָ¶¨Ä¬ÈÏÇý¶¯³ÌÐò
&nbs ......
CLR¿ÉÒÔʵÏÖDMLºÍDDLÁ½ÖÖ´¥·¢ÐÎʽ£¬µ«ÊDZ¾ÈËÒ»°ã²»½¨ÒéʹÓÃCLRµÄ´¥·¢Æ÷£¬Ö÷ÒªÊÇ¿¼Âǵ½Ð§ÂÊÎÊÌâ¡£±ÈÈçÎÒÃÇʹÓÃtriggerÀ´ÊµÏÖ·¢mailµÈ²Ù×÷ʱ£¬¾ÍÒª¿¼ÂÇpop3»òÊÇsmtpµÈ´ýʱ¼ä£¬ÒòΪtrigger±¾Ê¾ÍÊǸöÊÂÎñ£¬Ò²¾ÍÊÇ˵£¬ÔÚsmtpµÈ´ýʱ¼äÒ²ËãÔÚÁËÕû¸öÊÂÎñÖУ¬ÕâÑù¾Í»á´ó´óÓ°ÏìЧÂÊ¡£
1.CLR DML´¥·¢Æ÷
DMLÖ¸µÄÊÇÊý¾Ý²Ù×÷ÓïÑÔ£¬Ò²¾Í ......
½â¾ö·½·¨...
¹ØÓÚSQL°²×°±»¹ÒÆðµÄÐÞ¸´´ó¼Ò¿ÉÄܶ¼Óöµ½¹ýµ±SQL±»É¾³ýºóÐèÒªÖØа²×°Ê±£¬½øÈë°²×°½çÃæ¾Í»á³öÏÖSQL´íÎóÌáʾ£º
´ÓÇ°µÄ°²×°³ÌÐò²Ù×÷ʹ°²×°³ÌÐò²Ù×÷¹ÒÆð£¬ÐèÒªÖØÐÂÆô¶¯¼ÆËã»ú
È»¶øÕâЩ¶¼Êǰ׷Ѿ¢£¬²»¹ÜÄãÖØÐÂÆô¶¯¶àÉÙ´ÎÒ²¶¼ÎÞ¼ÃÓÚÊ£¬ÏÂÃæÎҾͽ²½²ÔõÑùÄܹ»½â³ý°²×°»òÉý¼¶Ê±Îļþ±»¹ÒÆðµÄ²Ù×÷¡£
µã»÷ ¿ ......
1¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏ
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö× ......