吉大数据库应用技术在线作业一答案
- 格式:doc
- 大小:51.00 KB
- 文档页数:6
吉大《数据库应用技术》在线作业一答案
试卷总分:100 测试时间:-- 试卷得分:100
单选题
一、单选题(共 25 道试题,共 100 分。) 得分:100V
1. Given the following table:
TestTable C1 ----------- 12345 And if the following CLI calls are made:
SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
SQLSetEnvAttr( henv,
SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3,0); SQL
AllocHandle(SQL_HANDLE_DBC,henv,&hdbc); SQLConnect( hdbc, (SQLCHAR
*)"db",
SQL_NTS, (SQLCHAR *)"userid", SQL_NTS, (SQLCHAR *)"password", SQL_NTS );
SQLSetConnectAttr( hdbc, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF,
0);
SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); SQLPrepare(hstmt,(unsigned
char*)"select *from Test order by C1',SQL_NTS);
SQLBindCol(hstmt,1,SQL_C_SHORT,&data,0,NULL); SQLExecute(hstmt);
SQLFetch(hstmt); printf(Data:%i\n",data); SQLFetch(hstmt);
printf(Data:%i\n",data); SQLFetch(hstmt); printf(Data:%i\n",data);
SQLEndTran(SQL_HANDLE_ENV,henv,SQL_COMMIT); SQLFetch(hstmt);
printf(Data:%i\n",data); Which of the following will be returned by the
program?
A. Data: 1 Data: 2 Data: 3 Data: 3
B. Data: 1 Data: 2 Data: 3 Data: 4
C. Data: 1 Data: 2 Data: 3 Data: 1
D. Data: 1 Data: 2 Data: 3 Data: 5
满分:4 分 得分:4
2. Given the code: EXEC SQL DECLARE cursor1 CURSOR FOR SELECT
name,age,b_date FROM person; EXEC SQL OPEN cursor1; Under which of the
following situations will the above cursor be implicitly closed?
A. When a CLOSE statement is issued
B. When a COMMIT statement is issued
C. When there are no rows in the result set
D. When all rows are FETCHed from the result set
满分:4 分 得分:4
3. Given the application code: EXEC SQL DECLARE cur CURSOR WITH HOLD FOR
SELECT c1 FROM t1 EXEC SQL OPEN cur EXEC SQL FETCH cur INTO :hv /*
Statement 1 */ EXEC SQL COMMIT /* Statement 2 */ EXEC SQL FETCH cur INTO
:hv /* Statement 3 */ EXEC SQL ROLLBACK /* Statement 4 */ EXEC SQL CLOSE
cur /* Statement 5 */ If the table T1 has no rows in it, which statement
will cause the cursor "cur" to be closed first?
A. Statement 1 B. Statement 2
C. Statement 3
D. Statement 4
满分:4 分 得分:4
4. How many rows can be retrieved using a single SELECT INTO statement?
A. Only one row
B. As many as are in the result
C. As many as are host variables used in the call
D. As many as host variable array structures can hold
满分:4 分 得分:4
5. Given the table T1 with the following data: COL1 IDX ---- ---- A
single-threaded CLI application executes the following pseudocode in
sequence: SQLAllocHandle( SQL_HANDLE_ENV, NULL, &hEnv ) SQLAllocHandle(
SQL_HANDLE_DBC, hEnv, &hDbc ) SQLConnect( hDbc, "SAMPLE", SQL_NTS,
NULL,
SQL_NTS, NULL, SQL_NTS ) SQLSetConnectAttr( hDbc,
SQL_ATTR_AUTOCOMMIT,
SQL_AUTOCOMMIT_ON ) SQLAllocHandle( SQL_HANDLE_STMT, hDbc, &hStmt )
SQLExecDirect( hStmt, "UPDATE table1 SET col1=10 WHERE idx=1", SQL_NTS )
SQLExecDirect( hStmt, "UPDATE table1 SET col1=20 WHERE idx=2", SQL_NTS )
SQLEndTran( SQL_HANDLE_DBC, hDbc, SQL_COMMIT ) SQLExecDirect( hStmt,
"UPDATE table1 SET col1=30 WHERE idx=1", SQL_NTS ) SQLExecDirect( hStmt,
"UPDATE table1 SET col1=40 WHERE idx=1", SQL_NTS ) SQLEndTran(
SQL_HANDLE_DBC, hDbc, SQL_ROLLBACK ) SQLExecDirect( hStmt, "SELECT
col1
FROM table1 WHERE idx=1", SQL_NTS ) Which of the following values for COL1
will be fetched when the sequence for the pseudocode listed above is
successfully executed?
A. 10
B. 20
C. 30
D. 40
满分:4 分 得分:4
6. Given the table T1 with the following data: C1 C2 -- -- 1 1 2 2 An
application issues the following SQL statements with AUTOCOMMIT disabled:
UPDATE t1 SET c1 = 10 WHERE c2 = 1 UPDATE t1 SET c1 = 20 WHERE c2 = 2
SAVEPOINT sp1 UPDATE t1 SET c1 = 30 WHERE c2 = 1 UPDATE t1 SET c1 = 40, c2
= 3 WHERE c2 = 2 SAVEPOINT sp1 UPDATE t1 SET c1 = 50 WHERE c2 = 1 UPDATE
t1 SET c1 = 60 WHERE c2 = 2 ROLLBACK TO SAVEPOINT sp1 UPDATE t1 SET c1 =
50 WHERE c2 = 3 COMMIT What is the result of the following query? SELECT
c1, c2 FROM t1 ORDER BY c2
A. 10 1 20 2
B. 30 1 50 3
C. 30 1 40 3 D. 10 1 50 3
满分:4 分 得分:4
7. Which of the following cursor definitions will define a cursor called
c2 that will fetch rows from table t2, and for every row fetched will