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

SQLÁ¬½Ó²éѯ(»ã×Ü)

Ò»¡¢½»²æÁ¬½Ó£¨CROSS JOIN£©
½»²æÁ¬½Ó£¨CROSS JOIN£©£ºÓÐÁ½ÖÖ£¬ÏÔʽµÄºÍÒþʽµÄ£¬²»´øON×Ӿ䣬·µ»ØµÄÊÇÁ½±íµÄ³Ë»ý£¬Ò²½ÐµÑ¿¨¶û»ý¡£
ÀýÈ磺ÏÂÃæµÄÓï¾ä1ºÍÓï¾ä2µÄ½á¹ûÊÇÏàͬµÄ¡£
Óï¾ä1£ºÒþʽµÄ½»²æÁ¬½Ó£¬Ã»ÓÐCROSS JOIN¡£
SELECT O.ID, O.ORDER_NUMBER, C.ID, C.NAME
from ORDERS O , CUSTOMERS C
WHERE O.ID=1;
Óï¾ä2£ºÏÔʽµÄ½»²æÁ¬½Ó£¬Ê¹ÓÃCROSS JOIN¡£
SELECT O.ID,O.ORDER_NUMBER,C.ID,C.NAME
from ORDERS O CROSS JOIN CUSTOMERS C
WHERE O.ID=1;
Óï¾ä1ºÍÓï¾ä2µÄ½á¹ûÊÇÏàͬµÄ£¬²éѯ½á¹ûÈçÏ£º
¶þ¡¢ÄÚÁ¬½Ó£¨INNER JOIN£©
ÄÚÁ¬½Ó£¨INNER JOIN£©£ºÓÐÁ½ÖÖ£¬ÏÔʽµÄºÍÒþʽµÄ£¬·µ»ØÁ¬½Ó±íÖзûºÏÁ¬½ÓÌõ¼þºÍ²éѯÌõ¼þµÄÊý¾ÝÐС££¨ËùνµÄÁ´½Ó±í¾ÍÊÇÊý¾Ý¿âÔÚ×ö²éѯÐγɵÄÖмä±í£©¡£
ÀýÈ磺ÏÂÃæµÄÓï¾ä3ºÍÓï¾ä4µÄ½á¹ûÊÇÏàͬµÄ¡£
Óï¾ä3£ºÒþʽµÄÄÚÁ¬½Ó£¬Ã»ÓÐINNER JOIN£¬ÐγɵÄÖмä±íΪÁ½¸ö±íµÄµÑ¿¨¶û»ý¡£
SELECT O.ID,O.ORDER_NUMBER,C.ID,C.NAME
from CUSTOMERS C,ORDERS O
WHERE C.ID=O.CUSTOMER_ID;
Óï¾ä4£ºÏÔʾµÄÄÚÁ¬½Ó£¬Ò»°ã³ÆΪÄÚÁ¬½Ó£¬ÓÐINNER JOIN£¬ÐγɵÄÖмä±íΪÁ½¸ö±í¾­¹ýONÌõ¼þ¹ýÂ˺óµÄµÑ¿¨¶û»ý¡£
SELECT O.ID,O.ORDER_NUMBER,C.ID,C.NAME
from CUSTOMERS C INNER JOIN ORDERS O ON C.ID=O.CUSTOMER_ID;
Óï¾ä3ºÍÓï¾ä4µÄ²éѯ½á¹û£º
Èý¡¢ÍâÁ¬½Ó£¨OUTER JOIN£©£ºÍâÁ¬²»µ«·µ»Ø·ûºÏÁ¬½ÓºÍ²éѯÌõ¼þµÄÊý¾ÝÐУ¬»¹·µ»Ø²»·ûºÏÌõ¼þµÄһЩÐС£ÍâÁ¬½Ó·ÖÈýÀࣺ×óÍâÁ¬½Ó£¨LEFT OUTER JOIN£©¡¢ÓÒÍâÁ¬½Ó£¨RIGHT OUTER JOIN£©ºÍÈ«ÍâÁ¬½Ó£¨FULL OUTER JOIN£©¡£
ÈýÕߵĹ²Í¬µãÊǶ¼·µ»Ø·ûºÏÁ¬½ÓÌõ¼þºÍ²éѯÌõ¼þ£¨¼´£ºÄÚÁ¬½Ó£©µÄÊý¾ÝÐС£²»Í¬µãÈçÏ£º
×óÍâÁ¬½Ó»¹·µ»Ø×ó±íÖв»·ûºÏÁ¬½ÓÌõ¼þµ¥·ûºÏ²éѯÌõ¼þµÄÊý¾ÝÐС£
ÓÒÍâÁ¬½Ó»¹·µ»ØÓÒ±íÖв»·ûºÏÁ¬½ÓÌõ¼þµ¥·ûºÏ²éѯÌõ¼þµÄÊý¾ÝÐС£
È«ÍâÁ¬½Ó»¹·µ»Ø×ó±íÖв»·ûºÏÁ¬½ÓÌõ¼þµ¥·ûºÏ²éѯÌõ¼þµÄÊý¾ÝÐУ¬²¢ÇÒ»¹·µ»ØÓÒ±íÖв»·ûºÏÁ¬½ÓÌõ¼þµ¥·ûºÏ²éѯÌõ¼þµÄÊý¾ÝÐС£È«ÍâÁ¬½Óʵ¼ÊÊÇÉÏ×óÍâÁ¬½ÓºÍÓÒÍâÁ¬½ÓµÄÊýѧºÏ¼¯£¨È¥µôÖظ´£©£¬¼´“È«Íâ=×óÍâ UNION ÓÒÍ┡£
˵Ã÷£º×ó±í¾ÍÊÇÔÚ“£¨LEFT OUTER JOIN£©”¹Ø¼ü×Ö×ó±ßµÄ±í¡£ÓÒ±íµ±È»¾ÍÊÇÓұߵÄÁË¡£ÔÚÈýÖÖÀàÐ͵ÄÍâÁ¬½ÓÖУ¬OUTER ¹Ø¼ü×ÖÊÇ¿ÉÊ¡ÂԵġ£
ÏÂÃæ¾ÙÀý˵Ã÷£º
Óï¾ä5£º×óÍâÁ¬½Ó£¨LEFT OUTER JOIN£©
SELECT O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME
from ORDERS O LEFT OUTER JOIN CUSTOMERS C ON C.ID=O.CUSTOMER_ID;
Óï¾ä6£ºÓÒÍâÁ¬


Ïà¹ØÎĵµ£º

oracle Ïà關µÄsql語¾ä

Êý¾Ý×Öµädict×ÜÊÇÊôÓÚOracleÓû§sysµÄ¡£
¡¡¡¡1¡¢Óû§£º
¡¡¡¡¡¡select username from dba_users;
¡¡¡¡¸Ä¿ÚÁî
¡¡¡¡¡¡alter user spgroup identified by spgtest;
¡¡¡¡2¡¢±í¿Õ¼ä£º
¡¡¡¡¡¡select * from dba_data_files;
¡¡¡¡¡¡select * from dba_tablespaces;//±í¿Õ¼ä
¡¡¡¡¡¡select tablespace_name,sum(bytes), sum(b ......

WEB°²È«½â¾ö·½°¸Ò»Ö®SQL×¢Èë·À·¶

Ò»¡¢SQL×¢Èë·À·¶
ÔÚÒ»¸öWEB¶¯Ì¬Ò³ÃæÖУ¨ÀýÈçaspx»òÕßjsp£©£¬Õâ¸öÒ³ÃæÔÊÐíÓû§ÔÚÊäÈë¿òÖÐÊäÈë×Ö·û£¬Õâ¸ö×Ö·û¿ÉÒÔ±»ÒýÈëµ½Êý¾Ý¿âÖÐÈ¥½øÐвéѯ£¨ÕâÀïµÄ²éѯÊÇͨÓõÄ˵·¨£¬Êµ¼ÊÉÏ°üÀ¨ÁËÔöɾ¸Ä²é£©²Ù×÷¡£Ò»¸öºÚ¿ÍÔÚÕâ¸öÊäÈë¿òÖÐÊäÈëÁËÒ»¸ö»ûÐβéѯ×Ö·û´®£¬´Ó¶ø¸Ä±äÁËÔ­ÓеIJéѯ£¬Õâ¿ÉÒÔ±»ÓÃÀ´²åÈ룬¸Ä±ä£¬»òË𺦺ǫ́Êý¾Ý¿â¡£Ôõà ......

»¹Ô­SQLʧ°Ü

Êý¾Ý¿âÖ´ÐÐexec sp_renamedb 'oldname','newname'Óï¾ä£¬ÖØÃüÃûºó£¬½«Êý¾Ý¿â±¸·ÝÎļþ»¹Ô­Ê±£¬»á³öÏÖ´íÎó£¬Èçͼ
ÒòÊýÊý¾ÝÎļþÓëÊý¾Ý¿âÃû³Æ²»Ò»Ö¡£
½â¾ö·½·¨£º¿ÉÒÔÕÒµ½Êý¾ÝÎļþµÄÃû³Æ£¬½«Êý¾Ý¿â»¹Ô­Ãû³Æ¸úÊý¾Ý¿âÎļþÒ»ÖµÄÃû³Æ£¬´Ëʱ»¹Ô­³É¹¦ºó£¬ÔÙÐÞ¸ÄÊý¾Ý¿âµÄÃû³Æ¡£
×¢£ºÊý¾Ý¿âÖØÃüʱ£¬Ð轫SQL·þÎñÆ÷Í£Ö¹£¬ÖØÃüÃûºóÔÙÖØÐ ......

sql´¥·¢Æ÷ʵÏÖ×Ô¶¯±àºÅ¸ñʽ


ʹÓô¥·¢Æ÷À´ÊµÏÖ
create table test(
id varchar(20),
sname varchar(20)
)
create TRIGGER [test_insert] ON [dbo].[test]
INSTEAD OF INSERT
AS
declare @str varchar(20)
declare @i integer
set @str = 'BV'+left(convert(char,getdate(),112),6)
select @i=isnull(max(cast(right(rtrim(id),len(id)-8 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ