Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

CÓïÑÔÓëSQL SERVERÊý¾Ý¿â

1.ʹÓÃCÓïÑÔÀ´²Ù×÷SQL SERVERÊý¾Ý¿â,²ÉÓÃODBC¿ª·ÅʽÊý¾Ý¿âÁ¬½Ó½øÐÐÊý¾ÝµÄÌí¼Ó,ÐÞ¸Ä,ɾ³ý,²éѯµÈ²Ù×÷¡£
step1:Æô¶¯SQLSERVER·þÎñ,ÀýÈç:HNHJ,¿ªÊ¼²Ëµ¥ ->ÔËÐÐ ->net start mssqlserver
step2:´ò¿ªÆóÒµ¹ÜÀíÆ÷,½¨Á¢Êý¾Ý¿âtest,ÔÚtest¿âÖн¨Á¢test±í(a varchar(200),b varchar(200))
step3:½¨Á¢ÏµÍ³DSN,¿ªÊ¼²Ëµ¥ ->ÔËÐÐ ->odbcad32,
  Ìí¼Ó->SQL SERVER
Ãû³Æ£ºcsql,·þÎñÆ÷£ºHNHJ
ʹÓÃÓû§Ê¹ÓõǼIDºÍÃÜÂëµÄSQLSERVERÑéÖ¤,µÇ¼ID:sa,ÃÜÂë:
  ¸ü¸ÄĬÈϵÄÊý¾Ý¿âΪ:test
...
²âÊÔÊý¾ÝÔ´£¬²âÊԳɹ¦£¬¼´DNSÌí¼Ó³É¹¦¡£ 2.cppÎļþÍêÕû´úÂë #include
#include
#include
#include
#include
#include
#include
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1 = SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
/*
cppÎļþ¹¦ÄÜ˵Ã÷£º
1.Êý¾Ý¿â²Ù×÷ÖеÄÌí¼Ó£¬Ð޸ģ¬É¾³ý£¬Ö÷ÒªÌåÏÖÔÚSQLÓï¾äÉÏ
2.²ÉÓÃÖ±½ÓÖ´Ðз½Ê½ºÍ²ÎÊýÔ¤±àÒëÖ´Ðз½Ê½Á½ÖÖ
*/
int main(){
RETCODE retcode;
UCHAR szDSN[SQL_MAX_DSN_LENGTH+1] = "csql",
szUID[MAXNAME] = "sa",
szAuthStr[MAXNAME] = "";
//SQLÓï¾ä
//Ö±½ÓSQLÓï¾ä
UCHAR sql[37] = "insert into test values('aaa','100')";
//Ô¤±àÒëSQLÓï¾ä
UCHAR pre_sql[29] = "insert into test values(?,?)";
//1.Á¬½ÓÊý¾ÝÔ´
//1.»·¾³¾ä±ú
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3,
SQL_IS_INTEGER);
//2.Á¬½Ó¾ä±ú
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLConnect(hdbc1, szDSN, 4, szUID, 2, szAuthStr, 0);
//ÅжÏÁ¬½ÓÊÇ·ñ³É¹¦
if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
printf("Á¬½Óʧ°Ü!\n");
} else {
//2.´´½¨²¢Ö´ÐÐÒ»Ìõ»ò¶àÌõSQLÓï¾ä
/*
1.·ÖÅäÒ»¸öÓï¾ä¾ä±ú(statement handle)
2.´´½¨SQLÓï¾ä
3.Ö´ÐÐÓï¾ä
4.Ïú»ÙÓï¾ä
*/
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);


Ïà¹ØÎĵµ£º

(ת)Ò»¸ö¼òµ¥µÄ´øͷβָÕëµ¥ÏòÁ´±í£¨CʵÏÖ£©

ÓÃCдÁËÒ»¸ö´øͷβָÕëµÄµ¥ÏòÁ´±í£¬½öÔÚβ²¿½øÐвåÈë²Ù×÷£¬ÔÚÈÎÒâλÖýøÐÐɾ³ý²Ù×÷¡£ÒòΪֻÓõ½ÕâôЩ¹¦ÄÜ£¬ÓÖÒòΪÀÁ£¬ËùÒÔûÓÐÀ©Õ¹¡£ÒòΪ²åÈëÊǹ̶¨ÔÚβ²¿½øÐУ¬´øÒ»¸öβָÕëµÄºÃ´¦ÊÇÏÔ¶øÒ×¼ûµÄ¡£µ±È»É¾³ýʱҪ¸¶³öһЩ¿ªÏú¡£
¡¡¡¡list.h
¡¡¡¡£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£ ......

SQL SERVERÖеÄÊý¾Ý¿â»Ö¸´¼¼Êõ


SQL ServerÊý¾Ý¿â±¸·ÝÓÐÁ½ÖÖ·½Ê½£¬Ò»ÖÖÊÇʹÓÃBACKUP DATABASE½«Êý¾Ý¿âÎļþ±¸·Ý³öÈ¥£¬ÁíÍâÒ»ÖÖ¾ÍÊÇÖ±½Ó¿½±´Êý¾Ý¿âÎļþmdfºÍÈÕÖ¾ÎļþldfµÄ·½Ê½¡£ÏÂÃ潫Ö÷ÒªÌÖÂÛһϺóÕߵı¸·ÝÓë»Ö¸´¡£±¾Îļٶ¨ÄúÄÜÊìÁ·Ê¹ÓÃSQL Server Enterprise Manager(SQL ServerÆóÒµ¹ÜÀíÆ÷)ºÍSQL Server Quwey Analyser(SQL Server²éѯ·ÖÎöÆ÷)
¡¡¡¡
¡ ......

Sql Server ÈÕÆÚ¸ñʽ»¯

Sql Server ÖÐÒ»¸ö·Ç³£Ç¿´óµÄÈÕÆÚ¸ñʽ»¯º¯Êý
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GE ......

ÎÄ˼´´ÐµÄSQL±ÊÊÔÌâ


ÌâÄ¿£ºÓÐAºÍBÁ©¸ö±í£¬¶¼¶¨ÒåÏàͬµÄÖ÷¼ü£¬Ð´³öSQLÓï¾äÕÒ³öA±íÖÐÓжøB±íÖÐûÓеļǼ£¬È»ºó°ÑûÓеļǼ²åÈëµ½B±íÖС£
SQLÓï¾äÈçÏ£º
CREATE TABLE  A_MINUS_B  AS              ---´´½¨Ò»¸ö²î¼¯±íA_MINUS_B ,×¢ÒâSELECT Óï¾äÒ»¶¨ÒªA±íÔÚÇ°¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ