תÌû sqlË÷Òý½á¹¹
Ò»¡¢ÉîÈëdz³öÀí½âË÷Òý½á¹¹
ʵ¼ÊÉÏ£¬Äú¿ÉÒÔ°ÑË÷ÒýÀí½âΪһÖÖÌØÊâµÄĿ¼¡£Î¢ÈíµÄSQL SERVERÌṩÁËÁ½ÖÖË÷Òý£º¾Û¼¯Ë÷Òý£¨clustered index£¬Ò²³Æ¾ÛÀàË÷Òý¡¢´Ø¼¯Ë÷Òý£©ºÍ·Ç¾Û¼¯Ë÷Òý£¨nonclustered index£¬Ò²³Æ·Ç¾ÛÀàË÷Òý¡¢·Ç´Ø¼¯Ë÷Òý£©¡£ÏÂÃ棬ÎÒÃǾÙÀýÀ´ËµÃ÷һϾۼ¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷ÒýµÄÇø±ð£º
Æäʵ£¬ÎÒÃǵĺºÓï×ÖµäµÄÕýÎı¾Éí¾ÍÊÇÒ»¸ö¾Û¼¯Ë÷Òý¡£±ÈÈ磬ÎÒÃÇÒª²é“°²”×Ö£¬¾Í»áºÜ×ÔÈ»µØ·¿ª×ÖµäµÄÇ°¼¸Ò³£¬ÒòΪ“°²”µÄÆ´ÒôÊÇ“an”£¬¶ø°´ÕÕÆ´ÒôÅÅÐòºº×ÖµÄ×ÖµäÊÇÒÔÓ¢ÎÄ×Öĸ“a”¿ªÍ·²¢ÒÔ“z”½áβµÄ£¬ÄÇô“°²”×Ö¾Í×ÔÈ»µØÅÅÔÚ×ÖµäµÄÇ°²¿¡£Èç¹ûÄú·ÍêÁËËùÓÐÒÔ“a”¿ªÍ·µÄ²¿·ÖÈÔÈ»ÕÒ²»µ½Õâ¸ö×Ö£¬ÄÇô¾Í˵Ã÷ÄúµÄ×ÖµäÖÐûÓÐÕâ¸ö×Ö£»Í¬ÑùµÄ£¬Èç¹û²é“ÕÅ”×Ö£¬ÄÇÄúÒ²»á½«ÄúµÄ×ֵ䷵½×îºó²¿·Ö£¬ÒòΪ“ÕÅ”µÄÆ´ÒôÊÇ“zhang”¡£Ò²¾ÍÊÇ˵£¬×ÖµäµÄÕýÎIJ¿·Ö±¾Éí¾ÍÊÇÒ»¸öĿ¼£¬Äú²»ÐèÒªÔÙÈ¥²éÆäËûĿ¼À´ÕÒµ½ÄúÐèÒªÕÒµÄÄÚÈÝ¡£ÎÒÃÇ°ÑÕâÖÖÕýÎÄÄÚÈݱ¾Éí¾ÍÊÇÒ»ÖÖ°´ÕÕÒ»¶¨¹æÔòÅÅÁеÄĿ¼³ÆΪ“¾Û¼¯Ë÷Òý”¡£
Èç¹ûÄúÈÏʶij¸ö×Ö£¬Äú¿ÉÒÔ¿ìËٵشÓ×Ô¶¯Öв鵽Õâ¸ö×Ö¡£µ«ÄúÒ²¿ÉÄÜ»áÓöµ½Äú²»ÈÏʶµÄ×Ö£¬²»ÖªµÀËüµÄ·¢Òô£¬Õâʱºò£¬Äú¾Í²»ÄÜ°´Õողŵķ½·¨ÕÒµ½ÄúÒª²éµÄ×Ö£¬¶øÐèҪȥ¸ù¾Ý“Æ«ÅÔ²¿Ê×”²éµ½ÄúÒªÕÒµÄ×Ö£¬È»ºó¸ù¾ÝÕâ¸ö×ÖºóµÄÒ³ÂëÖ±½Ó·µ½Ä³Ò³À´ÕÒµ½ÄúÒªÕÒµÄ×Ö¡£µ«Äú½áºÏ“²¿Ê×Ŀ¼”ºÍ“¼ì×ֱ픶ø²éµ½µÄ×ÖµÄÅÅÐò²¢²»ÊÇÕæÕýµÄÕýÎĵÄÅÅÐò·½·¨£¬±ÈÈçÄú²é“ÕÅ”×Ö£¬ÎÒÃÇ¿ÉÒÔ¿´µ½Ôڲ鲿Ê×Ö®ºóµÄ¼ì×Ö±íÖГÕÅ”µÄÒ³ÂëÊÇ672Ò³£¬¼ì×Ö±íÖГÕÅ”µÄÉÏÃæÊÇ“³Û”×Ö£¬µ«Ò³ÂëÈ´ÊÇ63Ò³£¬“ÕÅ”µÄÏÂÃæÊÇ“åó”×Ö£¬Ò³ÃæÊÇ390Ò³¡£ºÜÏÔÈ»£¬ÕâЩ×Ö²¢²»ÊÇÕæÕýµÄ·Ö±ðλÓÚ“ÕÅ”×ÖµÄÉÏÏ·½£¬ÏÖÔÚÄú¿´µ½µÄÁ¬ÐøµÄ“³Û¡¢ÕÅ¡¢åó”Èý×Öʵ¼ÊÉϾÍÊÇËûÃÇÔڷǾۼ¯Ë÷ÒýÖеÄÅÅÐò£¬ÊÇ×ÖµäÕýÎÄÖеÄ×ÖÔڷǾۼ¯Ë÷ÒýÖеÄÓ³Éä¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÕâÖÖ·½Ê½À´ÕÒµ½ÄúËùÐèÒªµÄ×Ö£¬µ«ËüÐèÒªÁ½¸ö¹ý³Ì£¬ÏÈÕÒµ½Ä¿Â¼ÖеĽá¹û£¬È»ºóÔÙ·µ½ÄúËùÐèÒªµÄÒ³Âë¡£ÎÒÃÇ°ÑÕâÖÖĿ¼´¿´âÊÇĿ¼£¬ÕýÎÄ´¿´âÊÇÕýÎĵÄÅÅÐò·½Ê½³ÆΪ“·Ç¾Û¼¯Ë÷Òý”¡£
ͨ¹ýÒÔÉÏÀý×Ó£¬ÎÒÃÇ¿ÉÒÔÀí½âµ½Ê²Ã´ÊÇ“¾Û¼¯Ë÷Òý”ºÍ“·Ç¾Û¼¯Ë÷Òý”¡£½øÒ»²½ÒýÉêһϣ¬ÎÒÃÇ¿ÉÒÔºÜÈÝÒ×µÄÀí½â£ºÃ¿¸ö±íÖ»ÄÜÓÐÒ»¸ö¾Û¼¯Ë
Ïà¹ØÎĵµ£º
#ÐÂÔöÒ»¸ö×ֶΣ¬Ä¬ÈÏֵΪ0£¬·Ç¿Õ£¬×Ô¶¯Ôö³¤£¬Ö÷¼ü
alter table tabelname add new_field_name field_type default 0 not null auto_increment ,add primary key (new_field_name);
#Ôö¼ÓÒ»¸öÐÂ×Ö¶Î
alter table tableName add new_field_name field_type;
alter table tableNam ......
1. ¸´ÖƱí½á¹¹
Sql´úÂë
1. select * into B from A where 1=0;
select * into B from A where 1=0;
2.¸´ÖƱí¼Ç¼ ¸´ÖÆijЩ×Ö¶Î
Sql´úÂë
1. insert into B(a, b, c) select d, e, f from A;
insert into B(a, b, c) select d, e, f from A;
¸´Ö ......
asc °´ÉýÐòÅÅÁÐ
desc °´½µÐòÅÅÁÐ
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý ......
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBac ......
SQL ServerÖÐÁª»ú´ÔÊé
SQL Server timestamp Êý¾ÝÀàÐÍÓëʱ¼äºÍÈÕÆÚÎ޹ء£SQL Server timestamp ÊǶþ½øÖÆÊý×Ö£¬Ëü±íÃ÷Êý¾Ý¿âÖÐÊý¾ÝÐ޸ķ¢ÉúµÄÏà¶Ô˳Ðò¡£ÊµÏÖ timestamp Êý¾ÝÀàÐÍ×î³õÊÇΪÁËÖ§³Ö SQL Server »Ö¸´Ëã·¨¡£Ã¿´ÎÐÞ¸Äҳʱ£¬¶¼»áʹÓõ±Ç°µÄ @@DBTS Öµ¶ÔÆä×öÒ»´Î±ê¼Ç£¬È»ºó @@D ......