ʵÓÃSQL語¾ä
http://blog.csdn.net/fenglibing/archive/2007/10/24/1841537.aspx
1¡¢½«Ò»¸ö±íÖеÄÄÚÈÝ¿½±´µ½ÁíÍâÒ»¸ö±íÖÐ
insert into testT1(a1,b1,c1) select a,b,c from test;
insert into testT select * from test; (Ç°ÌáÊÇ兩個±íµÄ結構ÍêÈ«Ïàͬ)
insert into notebook(id,title,content)
select notebook_sequence.NEXTVAL,first_name,last_name from students;
×¢:a1,b1,c1ÊÇ現ÔÚ±íÖеÄ×Ö¶ÎÃû¡£A,b,cÊÇÔ±íÖеÄ×Ö¶ÎÃû
¿½±´µ¥ÌõÊý¾Ý
insert into a (select '123' as id, temp,temp2 from b where id=10)
2¡¢²éÕÒÖظ´¼Ç¼
SELECT DRAWING,DSNO from EM5_PIPE_PREFAB
WHERE ROWID!=(SELECT MAX(ROWID) from EM5
_PIPE_PREFAB D
WHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING AND
EM5_PIPE_PREFAB.DSNO=D.DSNO);
3¡¢É¾³ýÖظ´¼Ç¼
DELETE from EM5_PIPE_PREFAB
WHERE ROWID!=(SELECT MAX(ROWID) from EM5
_PIPE_PREFAB D
WHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING AND
EM5_PIPE_PREFAB.DSNO=D.DSNO);
4¡¢復ÖƱí結構
ÔÚORACLEÖÐ: create table new_table as select * from old_table where rownum < 1;
ÔÚSQL SERVERÖÐ:˵Ã÷£º¸´ÖƱí(Ö»¸´Öƽṹ,Ô´±íÃû£ºa бíÃû£ºb)
¡¡¡¡SQL: select * into b from a where 1<>1 ¡¡
Óï¾ä
5¡¢Ò»´Î刪³ý¶à個×Ö¶Î
alter table TEST_A drop (TEST_num,test_name);
6¡¢實現Ò»個±íµÄ備·Ý
create table tableName_bak as select * from tableName;
7¡¢創½¨兩個±íµÄÖ÷Íâ鍵關聯
--ÏÈ創½¨Ö÷±í
create table t1(id int,stu_name varchar(50));
--為Ö÷±íÔö¼Ó³Ö¾ÃµÄÖ÷鍵約Êø
alter table t1 add(constraint t1_id primary key(id) deferrable);
--創½¨從±í£¬²¢將從±íµÄid設為Ö÷鍵
create table t2(id int primary key,sex varchar(10),address varchar(50));
--為從±íÔö¼ÓÍâ鍵約Êø£¬該約Êø來×ÔÓÚÖ÷±íËù創½¨µÄ約Êø×Ö¶Î
--當從Ö÷±íÖÐ刪³ý記錄時£¬×Ô動刪³ý從±íÖÐ與Ö®Ïà對µÄ¾ßÓÐÏàͬidµÄ記錄
--Ĭ
Ïà¹ØÎĵµ£º
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. Ö´ÐÐsqlÓï¾ä
int sqlite3_exec(sqlite3*£¬ const char *sql£¬ sqlite3_callbacksql Óï·¨
£¬ void *£¬ char **errmsg );
Õâ¾ÍÊÇÖ´ÐÐÒ»Ìõ sql Óï¾äµÄº¯Êý¡£
µÚ1¸ö²ÎÊý²»ÔÙ˵ÁË£¬ÊÇÇ°Ãæopenº¯ÊýµÃµ½µÄÖ¸Õ롣˵ÁËÊǹؼüÊý¾Ý½á¹¹¡£
µÚ2¸ö²ÎÊýconst char ......
l ÔÚ³ÌÐòÖÐÆ´½ÓSQLÃüÁî
¿ÉÊÇÈçºÎÔÚC#³ÌÐòÖÐÔËÐÐÄØ£¿ÎÒÃǼǵÃÔÚÆÕͨµÄSQL²éѯÖУ¬Ò»°ãÐèÒª°Ñ²éѯÓï¾ä¸³Öµ¸øSalCommand.CommandTextÊôÐÔ£¬ÕâÀïÒ²¾ÍÏñÆÕͨµÄSQL²éѯÓï¾äÒ»Ñù£¬½«ÕâЩÓï¾ä¸³¸øSqlCommand.CommandTextÊôÐÔ¼´¿É¡£Òª×¢ÒâµÄÒ»µãÊÇ£¬ÆäÖеÄ"GO"Óï¾ä±êÖ¾×ÅSQLÅú´¦ÀíµÄ½áÊø£¬±àдSQL½Å±¾ÊÇÐèÒªµÄ£¬µ«ÊÇÔÚÕâÀïÊDz ......
¡¡¡¡SQL»ù±¾Óï¾ä
Ò». SQLµÄËÄÌõ×î»ù±¾µÄÊý¾Ý²Ù×÷Óï¾äΪInsert£¬Select£¬UpdateºÍDelete¡£
¶þ.Ê×ÏÈÎÒÃÇʹÓÃCREATE TABLEÓï¾äÀ´´´½¨Ò»¸ö±í¡£DDLÓï¾ä¶ÔÊý¾Ý¿â¶ÔÏóÈç±í¡¢ÁкÍÊÓ½øÐж¨Òå¡£ËüÃDz¢²»¶Ô±íÖеÄÐнøÐд¦Àí£¬ÕâÊÇÒòΪDDLÓï¾ä²¢²»´¦ÀíÊý¾Ý¿âÖÐʵ¼ÊµÄÊý¾Ý¡£ÕâЩ¹¤×÷ÓÉÁíÒ» ......
use AdventureWorks
GO
SELECT c.LastName from Person.Contact c;
SELECT * from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID; n
SELECT ProductID,Name,ProductNumber,ReorderPoint
from Production.Product
where ProductID in( select ProductID fro ......
Microsoft SQL Server ÏÖÔھ߱¸Óë Microsoft Windows .NET Framework µÄ¹«¹²ÓïÑÔÔËÐÐʱ (CLR) ×é¼þ¼¯³ÉµÄ¹¦ÄÜ¡£CLR ΪÍйܴúÂëÌṩ·þÎñ£¬ÀýÈç¿çÓïÑÔ¼¯³É¡¢´úÂë·ÃÎÊ°²È«ÐÔ¡¢¶ÔÏóÉú´æÆÚ¹ÜÀíÒÔ¼°µ÷ÊԺͷÖÎöÖ§³Ö¡£¶ÔÓÚ SQL Server Óû§ºÍÓ¦ÓóÌÐò¿ª·¢ÈËÔ±À´Ëµ£¬CLR ¼¯³ÉÒâζ×ÅÄúÏÖÔÚ¿ÉÒÔʹÓÃÈκ ......