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

SQL Server 2005ÖеÄT SQLÔöÇ¿A

TOP ÔöÇ¿¡£¿ÉÒÔÖ¸¶¨Ò»¸öÊý×Ö±í´ïʽ£¬ÒÔ·µ»ØҪͨ¹ý²éѯӰÏìµÄÐÐÊý»ò°Ù·Ö±È£¬»¹¿ÉÒÔ¸ù¾ÝÇé¿öʹÓñäÁ¿»ò×Ó²éѯ¡£
¿ÉÒÔÔÚDELETE¡¢UPDATEºÍINSERT²éѯÖÐʹÓÃTOPÑ¡Ïî¡£
2¡¢¸üºÃµØÌæ»»SET ROWCOUNTÑ¡Ïʹ֮¸üΪÓÐЧ¡£
OUTPUT
1¡¢SQL Server 2005ÒýÈëÒ»¸öеÄOUTPUT×Ӿ䣬ÒÔʹÄú¿ÉÒÔ³åÐÞ¸ÄÓï¾ä(INSERT¡¢UPDATE¡¢DELETE)Öн«Êý¾Ý·µ»Øµ½±í±äÁ¿ÖС£
2¡¢ÐµÄOUTPUT×Ó¾ÖµÄÓ﷨Ϊ£º
OUTPUT INTO @table_variable
¿ÉÒÔͨ¹ýÒýÓòåÈëµÄ±í»òɾ³ýµÄ±íÀ´·ÃÎʱ»Ð޸ĵÄÐеľÉ/ÐÂÓ°Ïó£¬Æ䷽ʽÓë·ÃÎÊ´¥·¢Æ÷ÀàËÆ¡£ÔÚINSERTÓï¾äÖУ¬Ö»ÄÜ·ÃÎʲåÈëµÄ±í¡£ÔÚDELETEÓï¾äÖУ¬Ö»ÄÜ·ÃÎÊɾ³ýµÄ±í¡£ÔÚUPDATEÓï¾äÖУ¬¿ÉÒÔ·ÃÎʲåÈëµÄ±íºÍɾ³ýµÄ±í¡£
USE demo
GO
CREATE TABLE tt
(
id INT IDENTITY,
c1 VARCHAR(15)
)
GO
INSERT INTO tt VALUES ('r1')
INSERT INTO tt VALUES ('r2')
INSERT INTO tt VALUES ('r5')
INSERT INTO tt VALUES ('r6')
INSERT INTO tt VALUES ('r7')
INSERT INTO tt VALUES ('r8')
INSERT INTO tt VALUES ('r9')
INSERT INTO tt VALUES ('r10')
DECLARE @del AS TABLE (deletedId INT, deletedValue VARCHAR(15))
DELETE tt
OUTPUT DELETED.id, DELETED.c1 INTO @del
WHERE id < 3
SELECT * from @del
GO
-----------------------------------------------
USE demo
GO
CREATE TABLE toptest (column1 VARCHAR(150))
GO
INSERT INTO toptest VALUES('t1')
INSERT INTO toptest VALUES('t2')
INSERT INTO toptest VALUES('t3')
INSERT INTO toptest VALUES('t4')
INSERT INTO toptest VALUES('t5')
INSERT INTO toptest VALUES('t6')
INSERT INTO toptest VALUES('t7')
INSERT INTO toptest VALUES('t8')
SELECT * from toptest
GO
CREATE TABLE toptest2 (column2 VARCHAR(150))
GO
INSERT INTO toptest2 VALUES('c1')
INSERT INTO toptest2 VALUES('c2')
--ÉùÃ÷3¸ö±äÁ¿
DECLARE @a INT
DECLARE @b INT
DECLARE @c INT
--¸³Öµ
SET @a = 10
SET @b = 5
SELECT @c = @a/@b
--ʹÓüÆËã±í´ïʽ
SELECT TOP(@c) * from toptest
--ʹÓÃSELECTÓï¾ä×÷ΪÌõ¼þ
SELECT TOP(SELECT COUNT(*) from toptest2) *
from toptest
--Ö¸³ötop
DELETE TOP(2) toptest where column1>'t6'
--¸üÐÂtop
UPDATE TOP(2) toptest SET column1 = 'hi' where column1<='t2'
SELECT * from toptest


Ïà¹ØÎĵµ£º

SQLÈý´ó·¶Ê¾

µÚÒ»·¶Ê½:È·±£Ã¿ÁеÄÔ­×ÓÐÔ.
Èç¹ûÿÁÐ(»òÕßÿ¸öÊôÐÔ)¶¼ÊDz»¿ÉÔÙ·ÖµÄ×îСÊý¾Ýµ¥Ôª(Ò²³ÆΪ×îСµÄÔ­×Óµ¥Ôª),ÔòÂú×ãµÚÒ»·¶Ê½.
ÀýÈç:¹Ë¿Í±í(ÐÕÃû¡¢±àºÅ¡¢µØÖ·¡¢……)ÆäÖÐ"µØÖ·"Áл¹¿ÉÒÔϸ·ÖΪ¹ú¼Ò¡¢Ê¡¡¢ÊС¢ÇøµÈ¡£
µÚ¶þ·¶Ê½:ÔÚµÚÒ»·¶Ê½µÄ»ù´¡Éϸü½øÒ»²ã,Ä¿±êÊÇÈ·±£±íÖеÄÿÁж¼ºÍÖ÷¼üÏà¹Ø.
Èç¹ûÒ»¸ö¹ØϵÂú×ã ......

SQL³£ÓÃÓï¾ä


SQL³£ÓÃÓï¾ä
SQLÓï¾äÏÈǰдµÄʱºò£¬ºÜÈÝÒ×°ÑһЩÌØÊâµÄÓ÷¨Íü¼Ç£¬ÎÒÌØ´ËÕûÀíÁËÒ»ÏÂSQLÓï¾ä²Ù×÷¡£
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk ......

PL/SQLÁ¬½ÓOracle(Ãâ°²×°oracle¿Í»§¶Ë)

 
      ´ó¼Ò¶¼ÖªµÀ£¬ÓÃPL/SQLÁ¬½ÓOracle£¬ÊÇÐèÒª°²×°Oracle¿Í»§¶ËÈí¼þµÄ¡£ÓÐûҪÏë¹ý²»°²×°Oracle¿Í»§¶ËÖ±½ÓÁ¬½ÓOracleÄØ£¿
      ÆäʵÎÒÒ»Ö±ÏëÕâÑù×ö£¬ÒòΪÕâ¸ö¿Í»§¶ËʵÔÚÌ«ÈÃÈËÌÖÑáÁË£¡£¡£¡²»µ«»á°²×°Ò»¸öJDK£¬¶øÇÒ»¹»á°Ñ×Ô¼º·ÅÔÚ»·¾³±äÁ¿µÄ×îÇ°Ã棬»áÔì³É²»Ð ......

SQL²Ù×÷È«¼¯

ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ 
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE) 
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT) 
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CR ......

SQL Server 2005 ÖÐʹÓÃÕýÔò±í´ïʽƥÅä

CLR Óû§¶¨Ò庯ÊýÖ»ÊÇÔÚ .NET ³ÌÐò¼¯Öж¨ÒåµÄ¾²Ì¬·½·¨¡£CREATE FUNCTION Óï¾äÒÑÀ©Õ¹ÎªÖ§³Ö´´½¨ CLR
Óû§¶¨Ò庯Êý¡£
1¡¢´´½¨Êý¾Ý¿âÏîÄ¿
¡¡¡¡
2¡¢Ìí¼ÓÓû§¶¨Ò庯Êý
¡¡¡¡
ÒÔÏÂÊÇÑÝʾ´úÂ룺
Code
using
 System;
using
 System.Data;
using
 System.Data.SqlClient;
using
 System.Data.Sql ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ