《第11讲1--初始嵌入式SQL.pdf》由会员分享,可在线阅读,更多相关《第11讲1--初始嵌入式SQL.pdf(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、? An Introduction to Database System? ? ? ? ? ? ? An Introduction to Database System SQL? ?SQL? ? ? 1? 2? An Introduction to Database System ?SQL? ?SQL? 1 ?SQL 2 ?SQL? ? ? ?SQL 3 ? ?ODBC? An Introduction to Database System ?11?SQL ? ?4?8.1? An Introduction to Database System Video 11-1?SQL An Introd
2、uction to Database System ?SQL #include #include EXEC SQL BEGIN DECLARE SECTION; /*? */ char HSno9; char HSname20; char HSex2; int HSage; char Hdept20; EXEC SQL END DECLARE SECTION; /*? */ long SQLCODE; EXEC SQL INCLUDE sqlca; /*?SQL? */ int main() /*c? */ printf(Please input the sno:);/*? */ scanf(
3、%s, HSno); /* ?TEST?localhost? ?54321?SYSTEM/krms? */ EXEC SQL CONNECT TO TESTlocalhost:54321 AS CONN1 USER SYSTEM“ USING “manager; EXEC SQL SELECT Sno,Sname,Ssex,Sage,Sdept INTO:Hsno,:Hname,:Hsex,:Hage,:Hdept FROM Student WHERE Sno=:HSno; if (sqlca.sqlcode = 0) printf(n% - 9s% - 20s% - 2s% - 4s% -
4、20sn, Sno, Sname, Ssex, Sage, Sdept); printf(% - 9s% - 20s% - 2s% - 4s% - 20sn, Hsno, Hname, Hsex, HSage, Hdept); EXEC SQL DISCONNECT CONN1; return 0; An Introduction to Database System ?SQL? ? ?SQL?SQL? ? ? ?EXEC SQL? ?C? ? EXEC SQL ; ? ?EXEC SQL SELECT Sno,Sname,Ssex,Sage,Sdept INTO:Hsno,:Hname,:H
5、sex,:Hage,:Hdept FROM Student WHERE Sno=:givensno; An Introduction to Database System ?SQL? ? SQL? ? ? ? ? ? ? ? ?SQL ? ? ? ? ? ? ? ? (? ?SQL) ? ? ? ? ? ? ? An Introduction to Database System ? ? ? ?SQL? ? ? ? ? An Introduction to Database System 1 ? EXEC SQL CONNECT TO target AS connection-name USE
6、R user-name; ? target? ?: ?SQL? ?DEFAULT An Introduction to Database System ? EXEC SQL CONNECT TO target AS connection-name USER user-name; ? connect-name? ? ? ? EXEC SQL SET CONNECTION connection-name |DEFAULT; An Introduction to Database System 2 ? EXEC SQL BEGIN DECLARE SECTION; /*?*/ char Deptna
7、me20; char Hsno9; char Hsname20; char Hssex2; int HSage; int NEWAGE; EXEC SQL END DECLARE SECTION; /*?*/ long SQLCODE; EXEC SQL INCLUDE SQLCA; /*?SQL?*/ An Introduction to Database System 3 ?SQL? ? ?SQL? ? ? (CREATE) ? ? (GRANT,REVOKE?COMMIT?ROBACK) ? ? (UPDATE, INSERT, DELETE) ? ? (SELECT) An Intro
8、duction to Database System SELECT? ? ?8.2 ? EXEC SQL SELECT Sno,Sname,Ssex,Sage,Sdept INTO:Hsno,:Hname,:Hsex,:Hage,:Hdept FROM Student WHERE Sno=:givensno; /* ?INTO? */ /*? */ An Introduction to Database System SELECT? ? INTO?WHERE?HAVING? ? ? ? ? ?NULL ? ? ? ? ? ? ? ? ?11-3? An Introduction to Data
9、base System ? ? ?UPDATE?SET?WHERE? ? ?8.4 ?1? EXEC SQL UPDATE SC SET Grade=:newgrade /*?newgrade*/ WHERE Sno=:givensno AND Cno=?1?; /*?givensno*/ An Introduction to Database System 4 ? EXEC SQL DISCONNECT connection; An Introduction to Database System 5. ? ?8.1 ? EXEC SQL BEGIN DECLARE SECTION; char
10、 Deptname20; char HSNo9; char HSName20; char HSSex2; int HSAge; EXEC SQL END DECLARE SECTION; long SQLCODE; EXEC SQL INCLUDE SQLCA; ? ?SQL? An Introduction to Database System ? int main(void) /*C?*/ printf(“Please input the student number ); scanf(%s, Hsno); /*?Hsno?*/ EXEC SQL CONNECT TO TESTlocalh
11、ost:54321 AS CONN1 USER SYSTEM USING MANAGER; EXEC SQL SELECT Sno,Sname,Ssex,Sage,Sdept INTO:Hsno,:Hname,:Hsex,:Hage,:Hdept FROM Student WHERE Sno=:HSno; ?Test? ?SQL? An Introduction to Database System ? if (sqlca.sqlcode = 0) /* SQLCA?SQLCODE = 0 ? */ printf(n% - 9s% - 20s% - 2s% - 4s% - 20sn, Sno, Sname, Ssex, Sage, Sdept); printf(% - 9s% - 20s% - 2s% - 4s% - 20sn, Hsno, Hname, Hsex, HSage, Hdept); EXEC SQL DISCONNECT CONN1; ?