SQL ServerÖÐÔ¼ÊøµÄ½éÉÜ
ÕªÒª
¶ÔÓÚSQL ServerÖеÄÔ¼Êø£¬Ïë±Ø´ó¼Ò²¢²»ÊǺÜÄ°Éú¡£µ«ÊÇÔ¼ÊøÖÐÕæÕýµÄÄÚºÊÇʲô£¬²¢²»ÊǺܶàÈ˶¼ºÜÇå³þµÄ¡£±¾ÎÄÒÔÏêϸµÄÎÄ×ÖÀ´½éÉÜÁËʲôÊÇÔ¼Êø£¬ÒÔ¼°ÈçºÎÔÚÊý¾Ý¿â±à³ÌÖÐÓ¦ÓúÍʹÓÃÕâЩԼÊø£¬À´´ïµ½¸üºÃµÄ±à³ÌЧ¹û¡££¨±¾ÎIJ¿·ÖÄÚÈݲο¼ÁËSQL ServerÁª»úÊֲᣩ
ÄÚÈÝ
Êý¾ÝÍêÕûÐÔ·ÖÀà
ʵÌåÍêÕûÐÔ
ÓòÍêÕûÐÔ
ÒýÓÃÍêÕûÐÔ
Óû§¶¨ÒåÍêÕûÐÔ
PRIMARY KEYÔ¼Êø
DEFAULTÔ¼Êø
CHECKÔ¼Êø
UNIQUEÔ¼Êø
FOREIGN KEYÔ¼Êø
ÕýÎÄ
ÔÚÊý¾Ý¿â¹ÜÀíϵͳÖУ¬±£Ö¤Êý¾Ý¿âÖеÄÊý¾ÝÍêÕûÐÔÊǷdz£ÖØÒªµÄ¡£ËùνÊý¾ÝÍêÕûÐÔ£¬¾ÍÊÇÖ¸´æ´¢ÔÚÊý¾Ý¿âÖÐÊý¾ÝµÄÒ»ÖÂÐÔºÍÕýÈ·ÐÔ¡£Ô¼Êø¶¨Òå¹ØÓÚÁÐÖÐÔÊÐíÖµµÄ¹æÔò£¬ÊÇÇ¿ÖÆÍêÕûÐԵıê×¼»úÖÆ¡£Ê¹ÓÃÔ¼ÊøÓÅÏÈÓÚʹÓô¥·¢Æ÷¡¢¹æÔòºÍĬÈÏÖµ¡£²éѯÓÅ»¯Æ÷ҲʹÓÃÔ¼Êø¶¨ÒåÉú³É¸ßÐÔÄܵIJéѯִÐмƻ®¡£
SQL ServerÁª»ú´ÔÊéÖУ¬½«Êý¾ÝÍêÕûÐÔ½âÊÍÈçÏ£º“´æ´¢ÔÚÊý¾Ý¿âÖеÄËùÓÐÊý¾ÝÖµ¾ùÕýÈ·µÄ״̬¡£Èç¹ûÊý¾Ý¿âÖд洢Óв»ÕýÈ·µÄÊý¾ÝÖµ£¬Ôò¸ÃÊý¾Ý¿â³ÆΪÒÑɥʧÊý¾ÝÍêÕûÐÔ¡£”Ç¿ÖÆÊý¾ÝÍêÕûÐÔ¿ÉÈ·±£Êý¾Ý¿âÖеÄÊý¾ÝÖÊÁ¿¡£
ÀýÈ磬Èç¹ûÊäÈëÁË employee_id ֵΪ 123 µÄÖ°Ô±£¬ÄÇô¸ÃÊý¾Ý¿â²»Ó¦ÔÊÐíÆäËûְԱʹÓÃͬһ ID Öµ¡£Èç¹û¼Æ»®½« employee_rating ÁеÄÖµ·¶Î§É趨Ϊ´Ó 1 µ½ 5£¬ÔòÊý¾Ý¿â²»Ó¦½ÓÊÜ 6¡£Èç¹û±íÓÐÒ» dept_id ÁУ¬¸ÃÁд洢ְԱµÄ²¿ÃűàºÅ£¬ÔòÊý¾Ý¿âÓ¦Ö»ÔÊÐí½ÓÊܹ«Ë¾ÖеÄÓÐЧ²¿ÃűàºÅ¡£
Êý¾ÝÍêÕûÐÔ·ÖÀà
ÔÚSQL ServerÖУ¬¸ù¾ÝÊý¾ÝÍêÕûдëÊ©Ëù×÷ÓõÄÊý¾Ý¿â¶ÔÏóºÍ·¶Î§²»Í¬£¬¿ÉÒÔ½«Êý¾ÝÍêÕûÐÔ·ÖΪÒÔϼ¸ÖÖ¡£
ʵÌåÍêÕûÐÔ
ÓòÍêÕûÐÔ
ÒýÓÃÍêÕûÐÔ
Óû§¶¨ÒåÍêÕûÐÔ
SQL ServerÁª»ú´ÔÊéÖÐÖ¸Ã÷£º“¶Ô±í½øÐмƻ®ÓÐÁ½¸öÖØÒª²½Ö裺±êʶÁеÄÓÐЧֵºÍÈ·¶¨ÈçºÎÇ¿ÖÆÁÐÖеÄÊý¾ÝÍêÕûÐÔ¡£”
ʵÌåÍêÕûÐÔ
ʵÌåÍêÕûÐÔ¼òµ¥µÄ˵£¬¾ÍÊǽ«±íÖеÄÿһÐп´×÷Ò»¸öʵÌ塣ʵÌåÍêÕûÐÔÒªÇó±íµÄ±êʾ·ûÁлòÖ÷¼üµÄÍêÕûÐÔ¡£¿ÉÒÔͨ¹ý½¨Á¢Î¨Ò»Ë÷Òý¡¢PRIMARY KEYÔ¼Êø¡¢UNIQUEÔ¼Êø£¬ÒÔ¼°ÁеÄIDENTITYÊôÐÔÀ´ÊµÊ©ÊµÌåÍêÕûÐÔ¡£
ÓòÍêÕûÐÔ
ÓòÍêÕûÐÔÊÇÖ¸¸ø¶¨ÁеÄÊäÈëÓÐЧÐÔ¡£ÒªÇó±íÖÐÖ¸¶¨ÁеÄÊý¾Ý¾ßÓÐÕýÈ·µÄÊý¾ÝÀàÐÍ¡¢¸ñʽºÍÓÐЧµÄÊý¾Ý·¶Î§¡£Ç¿ÖÆÓòÓÐЧÐԵķ½·¨ÓУºÏÞÖÆÀàÐÍ£¨Í¨¹ýÊý¾ÝÀàÐÍ£©¡¢¸ñʽ£¨Í¨¹ý CHECK Ô¼ÊøºÍ¹æÔò£©»ò¿ÉÄÜÖµµÄ·¶Î§¡£ÓòÍêÕûÐÔͨ¹ý FOREIGN KEY Ô¼Êø¡¢CHECK Ô¼Êø¡¢DEFAULT ¶¨Òå¡¢NOT NULL ¶¨ÒåºÍ¹æÔòÀ´ÊµÏÖ¡£
ÒýÓÃÍêÕûÐÔ
Ïà¹ØÎĵµ£º
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLÏ°¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
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¿ÉÒÔÊ¡Â ......
1. ´æ´¢¹ý³Ì(¶¨Òå&±àд)
l ´´½¨´æ´¢¹ý³Ì
CREATE PROCEDURE storedproc1
AS
SELECT *
from tb_project
WHERE Ô¤¼Æ¹¤ÆÚ<= 90
ORDER BY Ô¤¼Æ¹¤ÆÚ DESC
GO
exec storedproc1
GO
l Ð޸Ĵ洢¹ý³Ì
ALTER PROCEDURE storedproc1
AS
SEL ......
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 ......