sql Íâ¼ü ɾ³ý
1¡£ÆóÒµ¹ÜÀíÆ÷
´ò¿ªÄ㽨ÓÐÍâ¼üµÄ±í££ÓÒ»÷±í££Éè¼Æ±í££ÔÚÉÏ·½µã¿ª’¹ÜÀíÔ¼Êø‘££½«¼¶Á¬É¾³ýºÍ¼¶Á¬¸üÐµĹµ´òÉϾͿÉÒÔÁË
2¡£²éѯ·ÖÎöÆ÷
alter table sc
add
constraint forei foreign key(sno)
REFERENCES student(sno)
ON DELETE CASCADE
ON UPDATE CASCADE
ON DELETE {CASCADE | NO ACTION}
Ö¸¶¨µ±±íÖб»¸ü¸ÄµÄÐоßÓÐÒýÓùØϵ£¬²¢ÇÒ¸ÃÐÐËùÒýÓõÄÐдӸ¸±íÖÐɾ³ýʱ£¬Òª¶Ô±»¸ü¸ÄÐвÉÈ¡µÄ²Ù×÷¡£Ä¬ÈÏÉèÖÃΪ NO ACTION¡£
Èç¹ûÖ¸¶¨ CASCADE£¬Ôò´Ó¸¸±íÖÐɾ³ý±»ÒýÓÃÐÐʱ£¬Ò²½«´ÓÒýÓñíÖÐɾ³ýÒýÓÃÐС£Èç¹ûÖ¸¶¨ NO ACTION£¬SQL Server ½«²úÉúÒ»¸ö´íÎ󲢻عö¸¸±íÖеÄÐÐɾ³ý²Ù×÷¡£
Èç¹û±íÖÐÒÑ´æÔÚ ON DELETE µÄ INSTEAD OF ´¥·¢Æ÷£¬ÄÇô¾Í²»Äܶ¨Òå ON DELETE µÄCASCADE ²Ù×÷¡£
ÀýÈ磬ÔÚ Northwind Êý¾Ý¿âÖУ¬Orders ±íºÍ Customers ±íÖ®¼äÓÐÒýÓùØϵ¡£Orders.CustomerID Íâ¼üÒýÓà Customers.CustomerID Ö÷¼ü¡£
Èç¹û¶Ô Customers ±íµÄijÐÐÖ´ÐÐ DELETE Óï¾ä£¬²¢ÇÒΪ Orders.CustomerID Ö¸¶¨ ON DELETE CASCADE ²Ù×÷£¬Ôò SQL Server ½«ÔÚ Orders ±íÖмì²éÊÇ·ñÓÐÓ뱻ɾ³ýµÄÐÐÏà¹ØµÄÒ»Ðлò¶àÐС£Èç¹û´æÔÚÏà¹ØÐУ¬ÄÇô Orders ±íÖеÄÏà¹ØÐн«Ëæ Customers ±íÖеı»ÒýÓÃÐÐһͬɾ³ý¡£
·´Ö®£¬Èç¹ûÖ¸¶¨ NO ACTION£¬ÈôÔÚ Orders ±íÖÐÖÁÉÙÓÐÒ»ÐÐÒýÓà Customers ±íÖÐҪɾ³ýµÄÐУ
Ïà¹ØÎĵµ£º
--select name from sysobjects where type='U' order by name
SELECT
(case when a.colorder=1 then d.name else '' end) ±íÃû,
-- a.colorder ×Ö¶ÎÐòºÅ,
a.name ×Ö¶ÎÃû,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) ±êʶ,
(case when (SELECT count(* ......
Èç: ±í:consume_record
×Ö¶Î:consume (moneyÀàÐÍ) date (datetimeÀàÐÍ)
ÇëÎÊÔõôдËÄÌõsqlÓï¾ä·Ö±ð°´ÈÕ,°´ÖÜ,°´ÔÂ,°´¼¾Í³¼ÆÏû·Ñ×ÜÁ¿.
Èç:1ÔÂ 1200Ôª
2ÔÂ 3400Ôª
3ÔÂ 2800Ôª
--°´ÈÕ
select sum(consume),day([date]) from& ......
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
¡¡¡¡2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
¡¡¡¡3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
¡¡¡¡4¡¢ÄÚ´æ²»×ã
¡¡¡¡5¡¢ÍøÂçËÙ¶ÈÂý
¡¡¡¡6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)
¡¡¡¡7¡¢Ëø»òÕßËÀËø(ÕâÒ²ÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐ ......
SQL Select IntoÓï¾ä
The SELECT INTO Statement
SELECT INTO Óï¾ä
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTOÓï¾ä³£ÓÃÀ´¸øÊý¾Ý±í½¨Á¢±¸·Ý»òÊÇÀúÊ·µµ°¸¡£
Syntax
Óï·¨
SELECT column_name(s) INTO newtable [IN externaldatabase] ......
SQL SERVER 2008 Òì²½²¶»ñ±íÊý¾ÝÐÞ¸Ä
дµÄ²»¶ÔµÄµØ·½Çë¸÷λָÕý£¬Ð´µÄÒ²±È½ÏÂÒ¡£½²¾¿Õâ¿´°É¡£^ ^
/*
SQL SERVER 2008 Òì²½²¶»ñ±íÊý¾ÝÐÞ¸Ä
SQL server 2008ΪÒì²½¸ú×ÙËùÓз¢ÉúÔÚÓû§±íÉϵÄÊý¾ÝÐÞ¸ÄÌṩÁËÄÚ½¨µÄ·½·¨,
¶ø²»ÐèÒª±àд×Ô¶¨ÒåµÄ´¥·¢Æ÷»òÕß²éѯ,±ä¸üÊý¾Ý²¶»ñÓµÓÐ×îСÐÔÄÜ¿ªÏú,¿ÉÒÔ
Ó ......