SQLν´Ê
1¡¢Î½´Ê ν´ÊÔÊÐíÄú¹¹ÔìÌõ¼þ£¬ÒÔ±ãÖ»´¦ÀíÂú×ãÕâЩÌõ¼þµÄÄÇЩÐС£
2¡¢Ê¹Óà IN ν´Ê
ʹÓà IN ν´Ê½«Ò»¸öÖµÓëÆäËû¼¸¸öÖµ½øÐбȽϡ£ÀýÈ磺
SELECT NAME from STAFF WHERE DEPT IN (20, 15)
´ËʾÀýÏ൱ÓÚ£º
SELECT NAME from STAFF WHERE DEPT = 20 OR DEPT = 15
µ±×Ó²éѯ·µ»ØÒ»×éֵʱ£¬¿ÉʹÓà IN ºÍ NOT IN ÔËËã·û¡£ÀýÈ磬ÏÂÁвéѯÁгö¸ºÔðÏîÄ¿ MA2100 ºÍ OP2012 µÄ¹ÍÔ±µÄÐÕ£º
SELECT LASTNAME from EMPLOYEE WHERE EMPNO IN (SELECT RESPEMP from PROJECT WHERE PROJNO='MA2100' OR PROJNO='OP2012')
¼ÆËãÒ»´Î×Ó²éѯ£¬²¢½«½á¹ûÁбíÖ±½Ó´úÈëÍâ²ã²éѯ¡£ÀýÈ磬ÉÏÃæµÄ×Ó²éѯѡÔñ¹ÍÔ±±àºÅ 10 ºÍ 330£¬¶ÔÍâ²ã²éѯ½øÐмÆË㣬¾ÍºÃÏó WHERE ×Ó¾äÈçÏ£º
WHERE EMPNO IN (10, 330)
×Ó²éѯ·µ»ØµÄÖµÁбí¿É°üº¬Áã¸ö¡¢Ò»¸ö»ò¶à¸öÖµ¡£
3¡¢Ê¹Óà BETWEEN ν´Ê
ʹÓà BETWEEN ν´Ê½«Ò»¸öÖµÓëij¸ö·¶Î§ÄÚµÄÖµ½øÐбȽϡ£·¶Î§Á½±ßµÄÖµÊÇ°üÀ¨ÔÚÄڵģ¬²¢¿¼ÂÇ BETWEEN ν´ÊÖÐÓÃÓڱȽϵÄÁ½¸ö±í´ïʽ¡£
ÏÂһʾÀýÑ°ÕÒÊÕÈëÔÚ $10,000 ºÍ $20,000 Ö®¼äµÄ¹ÍÔ±µÄÐÕÃû£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY BETWEEN 10000 AND 20000
ÕâÏ൱ÓÚ£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY >= 10000 AND SALARY <= 20000
ÏÂÒ»¸öʾÀýÑ°ÕÒÊÕÈëÉÙÓÚ $10,000 »ò³¬¹ý $20,000 µÄ¹ÍÔ±µÄÐÕÃû£º
SELECT LASTNAME from EMPLOYEE WHERE SALARY NOT BETWEEN 10000 AND 20000
4¡¢Ê¹Óà LIKE ν´Ê
ʹÓà LIKE ν´ÊËÑË÷¾ßÓÐijЩģʽµÄ×Ö·û´®¡£Í¨¹ý°Ù·ÖºÅºÍÏ»®ÏßÖ¸¶¨Ä£Ê½¡£
Ï»®Ïß×Ö·û(_)±íʾÈκε¥¸ö×Ö·û£¬°Ù·ÖºÅ(%)±íʾÁã»ò¶à¸ö×Ö·ûµÄ×Ö·û´®¡£
ÈκÎÆäËû±íʾ±¾ÉíµÄ×Ö·û¡£
ÏÂÁÐʾÀýÑ¡ÔñÒÔ×Öĸ\'S\'¿ªÍ·³¤¶ÈΪ 7 ¸ö×ÖĸµÄ¹ÍÔ±Ãû£º
SELECT NAME from STAFF WHERE NAME LIKE \'S_ _ _ _ _ _\'
ÏÂÒ»¸öʾÀýÑ¡Ôñ²»ÒÔ×Öĸ\'S\'¿ªÍ·µÄ¹ÍÔ±Ãû£º
SELECT NAME from STAFF WHERE NAME NOT LIKE \'S%\'
5¡¢Ê¹Óà EXISTS ν´Ê
¿ÉʹÓÃ×Ó²éѯÀ´²âÊÔÂú×ãij¸öÌõ¼þµÄÐеĴæÔÚÐÔ¡£ÔÚ´ËÇé¿öÏ£¬Î½´Ê EXISTS »ò NOT EXISTS ½«×Ó²éѯÁ´½Óµ½Íâ²ã²éѯ¡£
µ±Óà EXISTS ν´Ê½«×Ó²éѯÁ´½Óµ½Íâ²ã²éѯʱ£¬¸Ã×Ó²éѯ²»·µ»ØÖµ¡£Ïà·´£¬Èç¹û×Ó²éѯµÄ»Ø´ð¼¯°üº¬Ò»¸ö»ò¸ü¶à¸öÐУ¬Ôò EXISTS ν´ÊΪÕ棻Èç¹û»Ø´ð¼¯²»°üº¬ÈκÎÐУ¬Ôò EXISTS ν´ÊΪ¼Ù¡£
ͨ³£½« EXISTS ν´ÊÓëÏà¹Ø×Ó²éѯһÆðʹÓá£ÏÂÃæʾÀýÁгöµ±Ç°ÔÚÏîÄ¿(PROJECT) ±íÖÐûÓÐÏîµÄ²¿ÃÅ£º
SELECT DEPTNO, DEPTNAME from DEPARTMENT X WHERE NOT
Ïà¹ØÎĵµ£º
1 windowsµÇ¼ÕË»§¿Ú£ºEXEC ap_grantlogin 'windowsÓòÃû\ÓòÕË»§'
2 SQL µÇ¼ÕË»§:EXEC sp_addlogin 'ÕË»§Ãû','ÃÜÂë'
3 ´´½¨Êý¾Ý¿âÓû§:exec spgrantdbaccess 'µÇ¼ÕË»§','Êý¾Ý¿âÓû§'
¶þ ¸øÊý¾Ý¿âÓû§ÊÚȨ
grant ȨÏÞ on ±íÃû to Êý¾Ý¿âÓû§ ......
½ñÌìÔÚÏîÄ¿ÖÐÓÐÒ»ÎÊÌ⣬ÔÚÍøÉϲéѯÁËcaseµÄÓ÷¨£¬Ìû³öÀ´ºÍ´ó¼Ò·ÖÏíÏ¡£
ÎÊÌâÃèÊö£ºÔÚÒ»ÕűíÖÐÓÐÒ»×Ö¶ÎbitÀàÐÍ£¬±íʾ´ËÌõÊý¾ÝÊÇ·ñ±»Ëø¶¨£¬ÔÚÒ³ÃæÉÏÓÐÒ»°´Å¥ÊǶԴËÌõÊý¾Ý½øÐÐËø¶¨ºÍ½âËøµÄ£¬Ñ¡ÔñÒ³ÃæÖеÄÊý¾Ý£¬µã»÷Õâ¸ö°´Å¥£¬Èç¹ûÕâÌõÊý¾ÝÊÇËø¶¨µÄ£¬¾Í½âËø£»Èç¹ûÊÇδ˵¶¨µÄ¾ÍËø¶¨£¬ÕâÑù¾ÍÓÃÒ»ÌõÓï¾äÀ´ÊµÏÖ¡£ºóÀ´Ï ......
ÔÚÁгö±íÖÐËùÓÐ×Ö¶ÎÃûµÄʱºò£¬Óõ½ÁËÕâÑùÒ»¸öSQLº¯Êý£ºobject_id
ÕâÀïÎÒ½«Æä×÷ÓÃÓëÓ÷¨ÁгöÀ´£¬ºÃÈôó¼ÒÃ÷°×£º
OBJECT_ID£º
·µ»ØÊý¾Ý¿â¶ÔÏó±êʶºÅ¡£
Óï·¨
OBJECT_ID ( 'object' )
²ÎÊý
'object'
ҪʹÓõĶÔÏó¡£object µÄÊý¾ÝÀàÐÍΪ char »ò nchar¡£Èç¹û object µÄÊý¾ÝÀàÐÍÊÇ char£¬ÄÇôÒþÐÔ½«Æäת»»³É ncha ......
½«ExcelÎļþÊý¾Ý¿âµ¼ÈëSQL ServerµÄÈýÖÖ·½°¸
//·½°¸Ò»£º ͨ¹ýOleDB·½Ê½»ñÈ¡ExcelÎļþµÄÊý¾Ý£¬È»ºóͨ¹ýDataSetÖÐתµ½SQL Server
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel files(*.xls)|*.xls";
if(openFileDialog.ShowDialog()==DialogResult.OK)
{
FileInfo ......
Ò»Ö±¶¼ÏëÕÒ¸öʱ¼äÑо¿Ò»Ï£¬½ñÌ컨ÁËÒ»Ììʱ¼äȥʵ¼ùÁËһϣ¬·Ç³£ÓÐÓ᣿ÉÒÔ˵ÊÇÊý¾Ý¿âÀïÃæµÄ¾«»ª°É¡£»¹ºÃÎÒ½ñÌìȥŪÁ˼¸Ï£¬Ëä˵¶¼ÊÇЩ¼òµ¥µÄÓï¾ä£¬µ«ÊÇ×îÆðÂëÖªµÀÒÔºóÔÚÏîÄ¿¸ÃÔõôȥ×öÁË¡£ Ïл°ÉÙ˵¡£½øÈëÕýÌâ¡£
1.´´½¨SQL´æ´¢¹ý³Ì:
CREATE PROCEDURE stu_proc1//Ö¸¶¨¹ý³ÌÃû
@Sno varc ......