SQLÓï·¨×ܽá
ÕâÊÇÎÒ±ßѧ±ß×ܽáµÄ£¬×ܹ²»¨ÁËÒ»ÌìÒ»Ò¹µÄʱ¼ä£¬²é×ÊÁϺͿ´ÊÓƵÍê³ÉµÄ£¬µ«ÎÒ¶Ôµ¥Ðк¯ÊýºÍ¶àÐк¯ÊýûÓÐ×ö¹ý¶àµÄÑо¿£¬ÒòΪÕß¿ÉÒÔ²éÎĵµ¡£»¹ÓоÍÊǶà±í²éѯÑо¿Ò²±È½Ïdz£¬Õâ¿ÉÒÔÔÚÒÔºóÓõ½µÄʱºòÔÚ¾ßÌåÑо¿¡£ »¹ÓоÍÊÇÒªÊìϤÊý¾Ý¿âµÄ²Ù×÷£¬Ôöɾ¸Ä²é£¬ÕâЩ¶¼ÒªÏ൱ÊìÁ·£¬Íü¼ÇʱҪ¼°Ê±¿´±Ê¼Ç¡£
SQL
1.......Êý¾ÝÀàÐÍ
char(10)£¨Õâ¸öÊÇÓÃÀ´´æ´¢Ö¸¶¨´æ´¢´óСµÄ×Ö·û¿ª±ÙµÄ¿Õ¼äΪ10£©,
varchar2(10)£¨Õâ¸öÊÇÓÃÀ´´æ´¢×Ö·û£¬¿ª±ÙµÄ¿Õ¼äΪ10µ±´æ´¢µÄ×Ö·û¿Õ¼ä²»µ½10ʱ¶àÓàµÄ¿Õ¼ä×Ô¶¯Êջأ¬ÖÐÎÄÕ¾Á½¸ö¿Õ¼ä£©,number(10)£¨ÓÃÀ´´æ´¢ÕûÊý£©,number(10,3)£¨ÓÃÀ´´æ´¢Ð¡Êý£¬Ò»¹²10λСÊýÕ¼Èý룩,date£¨ÓÃÀ´´æ´¢ÈÕÆÚ£©¡£
2.......´´½¨±í
Àý£º
create table fg_user
( name char(10),
age number(3),
salary number(7,2),
birthday date
);
fg_userÊDZíÃû£¨fgÊÇǰ׺£©¡£
3.......²éѯ±í
desc fg_userÊDzéѯ±íµÄ£¨¿´¿´´´½¨ÁËÄÇЩÀàÈÝÈ磺name£¬age£¬salary£¬birthdayµÈ£©¡£
4.......Ïò±íÖÐдÈëÊý¾Ý£ºinsert into fg_user values('·ë¿¡','19','-700',','11-7ÔÂ-1990');
µ±ÓеÄÊý¾Ý²»È·¶¨Ê±¿ÉÒÔÓúóÃæÁ½ÖÖд·¨ÖеÄÒ»ÖÖ£º
insert into fg_user values('·ë¿¡',19,-700,'11-7ÔÂ-1990');
insert into fg_user values('»ÆСÃ÷',31,null,null);
insert into fg_user(name,age) values('ÀîÁ¬½Ü',41);
commit;
5.......Ìá½»±í
дÍêºóÒªÌá½»£¬²»È»²»±£´æ¡£Ìá½»ÊÇcommit
6.......²éѯÌá½»µÄ±íÖеÄÊý¾Ý£¨ÏÞÖƵÄÊÇÁÐ È磺select salary£©
select * from fg_user;
selectµÄʹÓ÷½·¨£ºselect name||'µÄ¹¤×Ê'||salary from fg_user;
select name,salary from fg_user;
±ðÃûµÄʹÓ㺠select name,salary from fg_user;
select name||'µÄ¹¤×Ê'||salary sss from fg_user;µ±ÓиñʽÏÞÖÆʱ±ðÃû¼ÓË«ÒýºÅ"s ss"¡£
È¥Öظ´ÐÐdistinct£¨²»ÏÔʾÖظ´µÄ£©£º
select distinct name,age,salary from fg_user;
Ïà¹ØÎĵµ£º
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLÏ°¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
¡¡¡¡1¡¢²é¿´±í¿Õ¼äµÄÃû³Æ¼°´óС
¡¡¡¡select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
¡¡¡¡from dba_tablespaces t, dba_data_files d
¡¡¡¡where t.tablespace_name = d.tablespace_name
¡¡¡¡group by t.tablespace_name;
¡¡¡¡
¡¡¡¡2¡¢²é¿´±í¿Õ¼äÎïÀíÎļþµÄÃû³Æ¼°´óС
¡¡¡¡select tablesp ......
Select * into customers from clients
(Êǽ«clients±íÀïµÄ¼Ç¼²åÈëµ½customersÖУ¬ÒªÇó£ºcustomers±í²»´æÔÚ£¬ÒòΪÔÚ²åÈëʱ»á×Ô¶¯´´½¨Ëü£»)
Insert into customers select * from clients
½â£ºInsert into customers select * from clients£©ÒªÇóÄ¿±ê±í£¨customers£©´æÔÚ£¬
ÓÉÓÚÄ¿±ê±íÒѾ´æÔÚ£¬ËùÒÔÎÒÃdzýÁ˲åÈëÔ´±í£ ......
ÔÚ±¾ÎÄÖУ¬´ËʾÀý±ê×¼À¶Í¼µÄ´æ´¢¹ý³ÌÃüÃû·½·¨Ö»ÊÊÓÃÓÚSQLÄÚ²¿£¬¼ÙÈçÄãÕýÔÚ´´½¨Ò»¸öеĴ洢¹ý³Ì£¬»òÊÇ·¢ÏÖÒ»¸öûÓа´ÕÕÕâ¸ö±ê×¼¹¹ÔìµÄ´æ´¢¹ý³Ì£¬¼´¿ÉÒԲο¼Ê¹ÓÃÕâ¸ö±ê×¼¡£
×¢ÊÍ£º¼ÙÈç´æ´¢¹ý³ÌÒÔsp_ Ϊǰ׺¿ªÊ¼ÃüÃûÄÇô»áÔËÐеÄÉÔ΢µÄ»ºÂý£¬ÕâÊÇÒòΪSQL Server½«Ê×ÏȲéÕÒϵͳ´æ´¢¹ý³Ì£¬ËùÒÔÎÒÃǾö²»ÍƼöʹÓÃsp_×÷Ϊǰ׺¡ ......