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

Ò»¸ösql¼òµ¥º¯ÊýʵÏÖÆ´½Ó×Ö·û´®

--²âÊÔÊý¾Ý
create table table1(AID int,NAME nvarchar(20))
create table table2 (BID int,NUMBER nvarchar(20))
insert into table1 select 1,'Tom' union all
select 2,'Jim'
insert into table2 select 1,20 union all
select 1,30
--º¯Êý
create function F_Str(@ID int)
returns nvarchar(100)
as
begin
   
    declare @S nvarchar(100)
    select return @S=isnull(@S+',','')+NUMBER from table2 where BID=@ID
   return @S
end
--²éѯ
select NAME,NUMBER = dbo.F_Str(AID) from table1
--½á¹û
-------------------
Tom    20,30
Jim    NULL


Ïà¹ØÎĵµ£º

¶¯Ì¬sqlÓï¾ä»ù±¾Óï·¨

1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
      Àý:      Select * from tableName
                Exec('select * from tableName')
        & ......

sqlÓï¾äÓÅ»¯2

£¨18£©ÓÃEXISTSÌæ»»DISTINCT£º
µ±Ìá½»Ò»¸ö°üº¬Ò»¶Ô¶à±íÐÅÏ¢(±ÈÈ粿ÃűíºÍ¹ÍÔ±±í)µÄ²éѯʱ,±ÜÃâÔÚSELECT×Ó¾äÖÐʹÓÃDISTINCT¡£Ò»°ã¿ÉÒÔ¿¼ÂÇÓÃEXISTÌæ»», EXISTS Ê¹²éѯ¸üΪѸËÙ,ÒòΪRDBMSºËÐÄÄ£¿é½«ÔÚ×Ó²éѯµÄÌõ¼þÒ»µ©Âú×ãºó,Á¢¿Ì·µ»Ø½á¹û¡£Àý×Ó£º
(µÍЧ):
SELECT DISTINCT DEPT_NO,DEPT_NAME  ......

SQL Êý¾Ý¿âÖ®Ò»

1.      SELECT
ʵÀý105
SELECT ID "±àºÅ",Name ÐÕÃû,
       Math_Score 'Êýѧ³É¼¨',  //ÔõôÓеÄÓÐAS,ÓеÄûÓÐ
       Music_Score AS ÒôÀֳɼ¨,
       English_Score AS Ó¢Îijɼ¨
f ......

SQLÊý¾Ý¿âÖ®¶þ

l  INNER JOIN
ÄÚÁ¬½ÓÊÇ×î³£¼ûµÄÒ»ÖÖÁ¬½Ó£¬ËüÒ³±»³ÆΪÆÕͨÁ¬½Ó£¬¶øE.FCodd×îÔç³Æ֮Ϊ×ÔÈ»Á¬½Ó¡£
ÏÂÃæÊÇANSI SQL£­92±ê×¼
select *  from    t_institution i
inner join t_teller t
on i.inst_no = t.inst_no  //˵Á½¸ö±íÖ®¼äµÄ¹ØϵÓÃON
where i.inst_no = "5801"
ÆäÖÐinner¿ÉÒÔÊ¡Â ......

ά»¤SQL serverµÄ28¸öСÎÊÌâ

1.ÈçºÎ´´½¨Êý¾Ý¿â
CREATE DATABASE student
2.ÈçºÎɾ³ýÊý¾Ý¿â
DROP DATABASE student
3.ÈçºÎ±¸·ÝÊý¾Ý¿âµ½´ÅÅÌÎļþ
BACKUP DATABASE student to disk=´c:S4.bak´
4.ÈçºÎ´Ó´ÅÅÌÎļþ»¹Ô­Êý¾Ý¿â
RESTORE DATABASE studnet from DISK = ´c:S4.bak´
5.ÔõÑù´´½¨±í£¿
CREATE TABLE Students (
&n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ