SQL Server 2000ÖеĴ¥·¢Æ÷ʹÓÃ
¿ÉÒÔ¶¨ÒåÒ»¸öÎÞÂÛºÎʱÓÃINSERTÓï¾äÏò±íÖвåÈëÊý¾Ýʱ¶¼»áÖ´ÐеĴ¥·¢Æ÷¡£
¡¡¡¡µ±´¥·¢INSERT´¥·¢Æ÷ʱ£¬ÐµÄÊý¾ÝÐоͻᱻ²åÈëµ½´¥·¢Æ÷±íºÍinserted±íÖС£inserted±íÊÇÒ»¸öÂß¼±í£¬Ëü°üº¬ÁËÒѾ²åÈëµÄÊý¾ÝÐеÄÒ»¸ö¸±±¾¡£inserted±í°üº¬ÁËINSERTÓï¾äÖÐÒѼǼµÄ²åÈ붯×÷¡£inserted±í»¹ÔÊÐíÒýÓÃÓɳõʼ»¯INSERTÓï¾ä¶ø²úÉúµÄÈÕÖ¾Êý¾Ý¡£´¥·¢Æ÷ͨ¹ý¼ì²éinserted±íÀ´È·¶¨ÊÇ·ñÖ´Ðд¥·¢Æ÷¶¯×÷»òÈçºÎÖ´ÐÐËü¡£inserted±íÖеÄÐÐ×ÜÊÇ´¥·¢Æ÷±íÖÐÒ»Ðлò¶àÐеĸ±±¾¡£
¡¡¡¡ÈÕÖ¾¼Ç¼ÁËËùÓÐÐÞ¸ÄÊý¾ÝµÄ¶¯×÷(INSERT¡¢UPDATEºÍDELETEÓï¾ä)£¬µ«ÔÚÊÂÎñÈÕÖ¾ÖеÄÐÅÏ¢ÊDz»¿É¶ÁµÄ¡£È»¶ø£¬inserted±íÔÊÐíÄãÒýÓÃÓÉINSERTÓï¾äÒýÆðµÄÈÕÖ¾±ä»¯£¬ÕâÑù¾Í¿ÉÒÔ½«²åÈëÊý¾ÝÓë·¢ÉúµÄ±ä»¯½øÐбȽϣ¬À´ÑéÖ¤ËüÃÇ»ò²ÉÈ¡½øÒ»²½µÄ¶¯×÷¡£Ò²¿ÉÒÔÖ±½ÓÒýÓòåÈëµÄÊý¾Ý£¬¶ø²»±Ø½«ËüÃÇ´æ´¢µ½±äÁ¿ÖС£
¡¡¡¡Ê¾Àý
¡¡¡¡ÔÚ±¾ÀýÖУ¬½«´´½¨Ò»¸ö´¥·¢Æ÷¡£ÎÞÂÛºÎʱ¶©¹º²úÆ·£¨ÎÞÂÛºÎʱÏòOrder Details±íÖвåÈëÒ»Ìõ¼Ç¼£©£¬Õâ¸ö´¥·¢Æ÷¶¼½«¸üÐÂProducts±íÖеÄÒ»ÁÐ(UnitsInStock)¡£ÓÃÔÀ´µÄÖµ¼õÈ¥¶©¹ºµÄÊýÁ¿Öµ¼´ÎªÐÂÖµ¡£
USE Northwind
CREATE TRIGGER OrdDet_Insert
ON [Order Details]
FOR INSERT
AS
UPDATE P SET
UnitsInStock = P.UnitsInStock – I.Quantity
from Products AS P INNER JOIN Inserted AS I
ON P.ProductID = I.ProductID
DELETE´¥·¢Æ÷µÄ¹¤×÷¹ý³Ì
¡¡¡¡µ±´¥·¢DELETE´¥·¢Æ÷ºó£¬´ÓÊÜÓ°ÏìµÄ±íÖÐɾ³ýµÄÐн«±»·ÅÖõ½Ò»¸öÌØÊâµÄdeleted±íÖС£deleted±íÊÇÒ»¸öÂß¼±í£¬Ëü±£ÁôÒѱ»É¾³ýÊý¾ÝÐеÄÒ»¸ö¸±±¾¡£deleted±í»¹ÔÊÐíÒýÓÃÓɳõʼ»¯DELETEÓï¾ä²úÉúµÄÈÕÖ¾Êý¾Ý¡£
¡¡¡¡Ê¹ÓÃDELETE´¥·¢Æ÷ʱ£¬ÐèÒª¿¼ÂÇÒÔϵÄÊÂÏîºÍÔÔò£º
¡¡¡¡·µ±Ä³Ðб»Ìí¼Óµ½deleted±íÖÐʱ£¬Ëü¾Í²»ÔÙ´æÔÚÓÚÊý¾Ý¿â±íÖУ»Òò´Ë£¬deleted±íºÍÊý¾Ý¿â±íûÓÐÏàͬµÄÐС£
¡¡¡¡·´´½¨deleted±íʱ£¬¿Õ¼äÊÇ´ÓÄÚ´æÖзÖÅäµÄ¡£deleted±í×ÜÊDZ»´æ´¢ÔÚ¸ßËÙ»º´æÖС£
¡¡¡¡·ÎªDELETE¶¯×÷¶¨ÒåµÄ´¥·¢Æ÷²¢²»Ö´ÐÐTRUNCATE TABLEÓï¾ä£¬ÔÒòÔÚÓÚÈÕÖ¾²»¼Ç¼TRUNCATE TABLEÓï¾ä¡£
¡¡¡¡Ê¾Àý
¡¡¡¡ÔÚ±¾ÀýÖУ¬½«´´½¨Ò»¸ö´¥·¢Æ÷£¬ÎÞÂÛºÎʱɾ³ýÒ»¸ö²úÆ·Àà±ð£¨¼´´ÓCategories±íÖÐɾ³ýÒ»Ìõ¼Ç¼£©£¬¸Ã´¥·¢Æ÷¶¼»á¸üÐÂProducts±íÖеÄDiscontinuedÁС£ËùÓÐÊÜÓ°ÏìµÄ²úÆ·¶¼±ê¼ÇΪ1£¬±êʾ²»ÔÙʹÓÃÕâЩ²úÆ·ÁË¡£
USE Northwind
Ïà¹ØÎĵµ£º
Ò»¡¢Ê¹ÓÃSqlConnection¶ÔÏóÁ¬½ÓSQL ServerÊý¾Ý¿â
1¡¢µÇ¼Êý¾Ý¿âµÄ·½Ê½ÎªSQL ServerÑé֤ģʽ
server=·þÎñÆ÷Ãû;database=Êý¾Ý¿âÃû³Æ;uid=Óû§;pwd=ÃÜÂë
2¡¢µÇ¼Êý¾Ý¿âµÄ·½Ê½ÎªWindowsÑé֤ģʽ
server=·þÎñÆ÷Ãû;database=Êý¾Ý¿âÃû³Æ;Integrated Security=SSPI
ÆäÖУ¬Integrated Security¼´Trusted_Connection,È¡Ö ......
Ò»°ãÓÃBCPÔÚ´¦ÀíÕâ¸öÊÂÇ飬µ«ÓÐʱҲÐèҪһЩÌØÊâµÄ´¦Àí£¬ÒÔÏÂÊÇÉú³É±íÖеÄһЩÊý¾Ý£¬´øÓÐwhereÌõ¼þµÄÑ¡ÔñÉú³ÉÊý¾Ý£¬ÊÇÎÒÒ»¸öͬÊÂÐ޸ĵģ¬Ö±½ÓÄùýÀ´ÓÃÁË£º
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc proc_insert_where (@tablename varchar(256),@where varchar(256 ......
use Master
go
if object_id('SP_SQL') is not null
drop proc SP_SQL
go
create proc [dbo].[SP_SQL](@ObjectName sysname)
as
set nocount on ;
declare @Print varchar(max)
if exists(select 1 from syscomments where ID=objec ......
PL/SQLʵÀý·ÖÎö
µÚÎåÕÂ
1¡¢PL/SQLʵÀý·ÖÎö
1£©ÔÚ¡¾SQLPlus Worksheet¡¿ÖÐÖ±½ÓÖ´ÐÐÈçÏÂSQL´úÂëÍê³ÉÉÏÊö²Ù×÷¡£(´´½¨±í)
¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D¨D
CREATE TABLE "SCOTT"."TESTTABLE" ("RECORDNUMBER" NUMBER(4) NOT NULL, "CURRENTDATE" DATE NOT NULL)
TABLESPACE "SYSTEM ......
sql isnullº¯ÊýµÄʹÓÃ
ISNULL
ʹÓÃÖ¸¶¨µÄÌæ»»ÖµÌæ»» NULL¡£
Óï·¨
ISNULL ( check_expression , replacement_value )
²ÎÊý
check_expression
½«±»¼ì²éÊÇ·ñΪ NULLµÄ±í´ïʽ¡£check_expression ¿ÉÒÔÊÇÈκÎÀàÐ͵ġ£
replacement_value
ÔÚ check_expression Ϊ NULLʱ½«·µ»ØµÄ±í´ïʽ¡£replacement_value ±ØÐëÓë chec ......