SQL 2000Óû§×Ô¶¨Ò庯Êý
Ò»¡£SQL Server µÄÈýÖÖ×Ô¶¨Ò庯Êý
“×Ô¶¨Ò庯Êý”ÊÇÎÒÃÇƽ³£µÄ˵·¨£¬¶ø“Óû§¶¨ÒåµÄº¯Êý”ÊÇ SQL Server ÖÐÊéÃæµÄ˵·¨¡£
SQL Server 2000 ÔÊÐíÓû§´´½¨×Ô¶¨Ò庯Êý£¬×Ô¶¨Ò庯Êý¿ÉÒÔÓзµ»ØÖµ¡£
×Ô¶¨Ò庯Êý·ÖΪ£º±êÁ¿Öµº¯Êý»ò±íÖµº¯Êý
Èç¹û RETURNS ×Ó¾äÖ¸¶¨Ò»ÖÖ±êÁ¿Êý¾ÝÀàÐÍ£¬Ôòº¯ÊýΪ±êÁ¿Öµº¯Êý¡£¿ÉÒÔʹÓöàÌõ Transact-SQL Óï¾ä¶¨Òå±êÁ¿Öµº¯Êý¡£
Èç¹û RETURNS ×Ó¾äÖ¸¶¨ TABLE£¬Ôòº¯ÊýΪ±íÖµº¯Êý¡£
±íÖµº¯ÊýÓÖ¿É·ÖΪ£ºÄÚǶ±íÖµº¯Êý£¨ÐÐÄÚº¯Êý£©»ò¶àÓï¾äº¯Êý
Èç¹û RETURNS ×Ó¾äÖ¸¶¨µÄ TABLE ²»¸½´øÁеÄÁÐ±í£¬Ôò¸Ãº¯ÊýΪÄÚǶ±íÖµº¯Êý¡£
Èç¹û RETURNS ×Ó¾äÖ¸¶¨µÄ TABLE ÀàÐÍ´øÓÐÁм°ÆäÊý¾ÝÀàÐÍ£¬Ôò¸Ãº¯ÊýÊǶàÓï¾ä±íÖµº¯Êý¡£
±êÁ¿Öµº¯ÊýʾÀý
CREATE FUNCTION dbo.Foo()
RETURNS int
AS
BEGIN
declare @n int
select @n=3
return @n
END
create function GetSex(@sex int)
returns varchar(2)-- ÓÃnvarchar(1)
as -- nvarchar:²»¹ÜÊÇÒ»¸ö×Ö·û»¹ÊÇÒ»¸öºº×Ö,¶¼´æΪ2¸ö×Ö½Ú
begin -- varchar:ºº×ÖÊÇ2¸ö×Ö½Ú,ÆäËû×Ö·û´æΪ1¸ö×Ö½Ú
declare @ssex varchar(2)-- ÓÃnvarchar(1)
if(@sex=1)
set @ssex='ÄÐ'
else
set @ssex='Å®'
return (@ssex)
end
µ÷Óãº
select id,username,dbo.GetSex(Sex) as sex ,loginnum from t_user
ÄÚǶ±íÖµº¯ÊýʾÀý
CREATE FUNCTION dbo.Foo()
RETURNS TABLE
AS
return select id, title from msgs
ÄÚǶ±íÖµº¯ÊýÖ»ÓÐÒ»¸ö select Óï¾ä¡£
¶àÓï¾ä±íÖµº¯ÊýʾÀý£¨²¿·Ö£©
CREATE FUNCTION FindUsers (@userid int )
RETURNS @FindUser TABLE (id int primary key, UserName varchar(30), RegDateTime DateTime,LoginNum int)
as
begin
insert into @FindUser Select ID, UserName,RegDateTime,LoginNum from T_User Where ID=@userid
return
end
µ÷Óãº
SELECT * from FindUsers(6)
×¢ÒâÆä RETURNS ²¿·Ö¡£
¶àÓï¾äº¯ÊýµÄÖ÷ÌåÖÐÔÊÐíʹÓÃÒÔÏÂÓï¾ä¡£Î´ÔÚÏÂÃæµÄÁбíÖÐÁг
Ïà¹ØÎĵµ£º
¼Æ»®ÓÚ2008ÄêµÚÒ»¼¾¶È·¢²¼µÄSQL Server 2008²»½ö¶ÔÔÓÐÐÔÄܽøÐÐÁ˸Ľø£¬»¹Ìí¼ÓÁËÐí¶àÐÂÌØÐÔ£¬±ÈÈçÐÂÌíÁËÊý¾Ý¼¯³É¹¦ÄÜ£¬¸Ä½øÁË·ÖÎö·þÎñ£¬±¨¸æ·þÎñ£¬ÒÔ¼°Office¼¯³ÉµÈµÈ¡£
¡¡¡¡SQL Server¼¯³É·þÎñ
¡¡¡¡SSIS(SQL Server¼¯³É·þÎñ)ÊÇÒ»¸öǶÈëʽӦÓóÌÐò£¬ÓÃÓÚ¿ª·¢ºÍÖ´ÐÐETL(½âѹËõ¡¢×ª»»ºÍ¼ÓÔØ)°ü¡£SSIS´úÌæÁËSQL 2000µÄDTS¡£Õ ......
ASP.NETÈçºÎÁ¬½ÓAccess»òSQL ServerÊý¾Ý¿â
Ê×ÏÈ¿´Ò»¸öÀý×Ó´úÂëƬ¶Ï:
³ÌÐò´úÂë:
--------------------------------------------------------------------------------
using System.Data;
using System.Data.OleDb;
......
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+ ......
ÔÚsqlserver2005ÖÐÓÃsqlÓï¾äд´úÂë,Éú³ÉÊý¾Ý±í
CREATE TABLE [t_ActivityRecord] (
[activityId] [nchar] (10) NOT NULL,
[activityName] [nvarchar] (50) NOT NULL,
[activityMark] [decimal] (18,3) NOT NULL,
[activityStatement] [ntext] NOT NULL,
[activityDateTime] [date] NOT ......
select *from customers
select *from orders
select customers.cust_id, orders.order_num from customers inner join orders on customers.cust_id=orders.cust_id
select customers.cust_id, orders.order_num from customers left outer join orders on customers.cust_id=orde ......
exists £¨sql ·µ»Ø½á¹û¼¯ÎªÕ棩
not exists (sql ²»·µ»Ø½á¹û¼¯ÎªÕ棩
ÈçÏ£º
±íA
ID NAME
1 A1
2 A2
3 A3
±íB
ID AID NAME
1 1 B1
2 & ......