標籤:microsoft 必須 交易記錄檔 沒有 通過 號碼 過程 位置 following
一、選擇題(1-25沒題1分26-30每題2分共35分)
1)假定有一個使用者表,表中包含欄位:userid (int)、username (varchar)、 password(varchar)、等,該表需要設定主鍵,以下說法正確的是()。(選擇兩項)
a)如果不能有同時重複的username和password,那麼username和password可以組合在一起作為主鍵。
b)此表設計主鍵時,根據選擇主鍵的最小性原則,最好採用userid作為主鍵。
c)此表設計主鍵時,根據選擇主鍵的最小性原則,最好採用username和password作為按鍵組合。
d) 如果採用userid作為主鍵,那麼在userid列輸入的數值,允許為空白。
2)Microsoft SQL Server 2000 在安裝的時候就建立的樣本使用者資料庫包括()。(選擇兩項)
a)Pubs
b)Master
c)Northwind
d)Msdb
3)以下()語句從表TABLE_NAME中提取前10條記錄。(選擇一項)
a)select from TABLE_NAME where rowcount=10
b)select TOP 10 from TABLE_NAME
c)select TOP of 10 from TABLE_NAME
d)select from TABLE_NAME where rowcount<=10
4) 從“產品”表裡查詢出價格高於產品名稱為“一次性紙杯”的產品的記錄,此SQL語句為()。(選擇一項)
a)SELECT FROM 產品WHERE 價格>‘一次性紙杯’
b)SELECT FROM 產品WHERE 價格>(SELECT FROM 產品WHERE 產品名稱>’ 一次性紙杯’
c)SELECT FROM 產品WHERE EXISTS 產品名稱=’ 一次性紙杯’
d)SELECT FROM 產品WHERE 價格>(SELECT 價格FROM 產品WHERE 產品名稱=’ 一次性紙杯’
5)尋找 student表中所有電話號碼(列名:telephone)的第一位為8或6,第三位為0的電話號碼()。(選擇一項)
a)SELECT telephone FROM student WHERE telephone LIKE ‘[8,6]%0‘
b)SELECT telephone FROM student WHERE telephone LIKE ‘(8,6)0%‘
c)SELECT telephone FROM student WHERE telephone LIKE ‘[8,6]_0%‘
d)SELECT telephone FROM student WHERE telephone LIKE ‘[8,6]_0‘
6)現有表book,欄位:id (int),title (varchar), price (float); 其中id欄位設為標識, 使用insert語句向book表中插入資料,以下語句錯誤的是()。(選擇一項)
a)insert into book (id,title,price) values(1,‘java‘,100)
b)insert into book (title,price) values(‘java‘,100)
c)insert into book values (‘java‘,100)
d)insert book values(‘java‘,100)
7)現有表Employee,欄位:id (int),firstname(varchar), lastname(varchar); 以下sql語句錯誤的是()。(選擇一項)
a)select firstname+‘.‘+lastname as ‘name‘ from employee )
b)select firstname+‘.‘+lastname=‘name‘ from employee
c)select ‘name‘=firstname+‘.‘+lastname from employee
d)select firstname,lastname from employee
8)在sql server 2000中,關於資料庫說法錯誤的是()。(選擇一項)
a)資料庫在磁碟上預設的儲存位置是:SQL Server安裝路徑/Microsoft SQL Server/MSSQL/Data
b)一個資料庫至少應包含一個資料庫檔案(.mdf)和一個交易記錄檔(.ldf)
c)只有當資料庫中不存在資料的情況下,才可以進行資料庫的收縮操作。
d)可以通過從A機器拷貝資料庫檔案和交易記錄檔至B機器,然後通過在B機器上執行相應的附加資料庫操作,實現資料庫從A機器到B機器的複製。
9)若要刪除book表中所有資料,以下語句錯誤的是()。(選擇兩項)
a)truncate table book
b)delete * from book
c)drop table book
d)delete from book
10)學產生績表grade中有欄位score(float),現在要把所有在55分至60之間的分數提高5分,以下sql語句正確的是()。(選擇兩項)
a)Update grade set score=score+5
b)Update grade set score=score+5 where score>=55 or score <=60
c)Update grade set score=score+5 where score between 55 and 60
d)Update grade set score=score+5 where score >=55 and score <=60
11)現有書目表book,包含欄位:price (float); 現在查詢一條書價最高的書目的詳細資料,以下語句正確的是()。(選擇兩項)
a)select top 1 from book order by price asc
b)select top 1 from book order by price desc
c)select top 1 from book where price= (select max (price)from book)
d)select top 1 from book where price= max(price)
12)現有書目表book,包含欄位:價格price (float),類別type(char); 現在查詢各個類別的平均價格、類別名稱,以下語句正確的是()。(選擇一項)
a)select avg(price),type from book group by type
b)select count(price),type from book group by price
c)select avg(price),type from book group by price
d)select count (price),type from book group by type
13)查詢student表中的所有非空email資訊, 以下語句正確的是()。(選擇一項)
a)Select email from student where email !=null
b)Select email from student where email not is null
c)Select email from student where email <> null
d)Select email from student where email is not null
14)成績表grade中欄位score代表分數,以下()語句返回成績表中的最低分。(選擇兩項)
a)select max(score) from grade
b)select top 1 score from grade order by score asc
c)Select min(score) from grade
d)select top 1 score from grade order by score desc
15)現有訂單表orders,包含使用者資訊userid, 產品資訊 productid, 以下()語句能夠返回至少被訂購過兩回的productid? (選擇一項)
a)select productid from orders where count(productid)>1
b)select productid from orders where max(productid)>1
c)select productid from orders where having count(productid)>1 group by productid_
d)select productid from orders group by productid having count(productid)>1
16)關於彙總函式,以下說法錯誤的是()。(選擇一項)
a)Sum返回運算式中所有數的總合,因此只能用於數字類型的列。
b)Avg返回運算式中所有數的平均值,可以用於數字型和日期型的列。
c)Max和Min可以用於字元型的列。
d)Count可以用於字元型的列。
17)使用以下()不可以進行模糊查詢。(選擇一項)
a)OR
b)Not between
c)Not IN
d)Like
18)關於多表聯結查詢,以下()描述是錯誤的。(選擇一項)
a)外聯結查詢返回的結果集行數可能大於所有符合聯結條件的結果集行數。
b)多表聯結查詢必須使用到JOIN關鍵字
c)內聯結查詢返回的結果是:所有符合聯結條件的資料。
d)在where子句中指定聯結條件可以實現內聯結查詢。
19)Sql語句:select * from students where SNO like ‘010[^0]%[A,B,C]%’,可能會查詢出的SNO是()。(選擇兩項)
a)01053090A #Hm3?
b)01003090A01
c)01053090D09
d)0101A01
20)關於Truncate table, 以下()描述是錯誤的。(選擇兩項)
a)Truncate table 可跟Where從句,根據條件進行刪除。
b)Truncate table 用來刪除表中所有資料。
c)觸發器對Truncate table無效。
d)delete 比Truncate table速度快。
21)建立一個名為‘Customers’的新表,同時要求新表中包含表‘clients’的所有記錄,sql語句是()。(選擇一項)
a)Select into customers from clients
b)Select into customers from clients
c)Insert into customers select from clients
d)Insert customers select * from clients
22)關於主鍵,以下()說法是錯誤的。(選擇兩項)
a)主鍵可以用來確保表中不存在重複的資料行。
b)一個表必須有一個主鍵。
c)一個表只能有一個主鍵。
d)只能對整數型列設定主鍵。
23)假設訂單表orders用來儲存訂單資訊,cid代表客戶編碼,money代表單次訂購額,現要查詢每個客戶的訂購次數和每個客戶的訂購總金額,下面()sql語句可以返回正確結果。(選擇一項)
a)select cid,count(distinct(cid)),sum(money) from orders group by cid
b)select cid,count(distinct(cid)),sum(money) from orders order by cid
c)select cid,count(cid),sum(money) from orders order by cid
d)select cid,count(cid),sum(money) from orders group by cid
24)現有客戶表customers(主鍵:客戶編碼cid),包含10行資料,訂單表orders(外鍵:客戶編碼cid),包含6條資料。執行sql語句:select * from customers right outer join orders on customers.cid=orders.cid。最多返回()條記錄。(選擇一項)
a)10
b)6
c)4
d)0
25)以下描述不正確的是
a)預存程序能夠實現較快的執行速度。
b)內嵌表值型函數相當於一個帶參數的視圖。
c)不指定所有者時,調用純量涵式會出錯。
d)可以通過視圖更改任意基表
26)Your database stores telephone numbers. Each telephone number is stored as an integer. You must format the telephone number to print on a report in the following format:
(999) 999-9999
You have selected the phone number into a local variable as follows:
DECLARE @PhoneNumber int Which statement will correctly format the number?
a)SELECT ‘Phone Number‘ = ‘(‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),3,0) + ‘)‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNurnber),3,3)+ ‘-‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),4,6)
b)SELECT ‘Phone Number‘ = ‘(‘ + SUBSTRING(CONVERT(varchar(10),@PhoneNuwber),3,1) + ‘)‘ + SUBSTRING(CONVERT(varcher(10), @PhoneNumber),3,4)+ ‘-‘ + SUBSTRING(CONVERT(varchar(10), @PhoneMumber),4,7)
c)SELECT ‘Phone Number‘ = ‘(‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),0,3) + ‘)‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),3,3)+ ‘-‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNurtiber),6,4)
d)SELECT ‘Phone Number‘ = ‘(‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),1,3) + ‘)‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),4,3)+ ‘-‘ + SUBSTRING(CONVERT(varchar(10), @PhoneNumber),7,4)
27)You are a database developer for Wide World Importers. You are creating a database that will store order information. Orders will be entered in a client/server application. Each time a new order is entered, a unique order number must be assigned. Order numbers must be assigned in ascending order. An average of 10,000 orders will be entered each day. You create a new table named Orders and add an OrderNumber column to this table. What should you do next?
a)Set the data type of the column to UniqueIdentifier.
b)Set the data type of the column to int, and set the IDENTITY property for the column.
c)Set the data type of the column to int. Create a user-defined function that selects the maximum order number in the table.
d)Set the data type of the column to int. Create a NextKey table, and add a NextOrder column to the table. Set the data type of the NextOrder column to int. Create a stored procedure to retrieve and update the value held in the NextKey.
28)You are creating a script that will execute this stored procedure. If the stored procedure executes successfully, it should report the year-to-date sales for the book title. If the stored procedure fails to execute, it should report the following message:
“No Sales Found”
How should you create the script?
a)DECLARE @retval int
DECLARE @ytd int
EXEC get_sales_for_title ‘Net Etiquette’, @ytd
IF @retval < 0
PRINT ‘No sales found’
ELSE
PRINT ‘Year to date sales: ’ + STR (@ytd)
GO
b)DECLARE @retval int
DECLARE @ytd int
EXEC get_sales_for_title ‘Net Etiquette’, @ytd OUTPUT
IF @retval < 0
PRINT ‘No sales found’
ELSE
PRINT ‘Year to date sales: ’ + STR (@ytd)
GO
c)DECLARE @retval int
DECLARE @ytd int
EXEC get_sales_for_title ‘Net Etiquette’,@retval OUTPUT
IF @retval < 0
PRINT ‘No sales found’
ELSE
PRINT ‘Year to date sales: ’ + STR (@ytd)
GO
d)DECLARE @retval int
DECLARE @ytd int
EXEC @retval = get_sales_for_title ‘Net Etiquette’, @ytd
OUTPUT
IF @retval < 0
PRINT ‘No sales found’
ELSE
PRINT ‘Year to date sales: ’ + STR (@ytd)
GO
29)You are a database developer for an insurance company. Information about the company‘s insurance policies is stored in a SQL Server 2000 database. You create a table named policy for this database by using the script shown below:
CREATE TABLE Policy
(
PolicyNumber int NOT NULL DEFAULT (0),
InsuredLastName CHAR (30) NOT NULL,
InsuredFirstName CHAR (20) NOT NULL,
InsuredBirthDate dattime NOT NULL,
PolicyDate datetime NOT NULL,
FaceAmount money NOT NULL,
CONSTRAINT PK_Policy PRIMARY KEY (PolicyNumber)
)
Each time the company sells a new policy, the policy must be assigned a unique policy number. The database must assign a new policy number when a new policy is entered. What should you do?
a)Create an INSTEAD OF INSERT trigger to generate a new policy number, and include the policy number in the data instead into the table.
b)Create an INSTEAD OF UPDATE trigger to generate a new policy number, and include the policy number in the data inserted into the table.
c)Create an AFTER UPDATE trigger to generate a new policy number, and include the policy number in the data inserted into the table.
d)Replace the DEFAULT constraint with a AFTER INSERT trigger that generates a new policy number and includes the policy number in the data inserted into the table.
30)You are a database developer for a marketing firm. You have designed a quarterly sales view. This view joins several tables and calculates aggregate information. You create a view. You want to provide a parameterised query to access the data contained in your view. The output will be used in other SELECT lists. How should you accomplish this goal?
a)Use an ALTER VIEW statement to add the parameter value to the view definition.
b)Create a stored procedure that accepts the parameter as input and returns a rowset with the result set.
c)Create a scalar user-defined function that accepts the parameter as input.
d)Create an inline user-defined function that accepts the parameter as input.
二、填空題(每空一分共25分)
1、關係R是1NF,若且唯若所有的基礎域僅包含____。
2、主關鍵字應該具有____性,__性,__性。
3、關係R是3NF,若且唯若R是2NF,並且所有非PK屬性都是__於PK。
4、Transact-SQL 語言套件含語言,語言,語言。
5、消除列重複的關鍵字是,使用_操作符從多個查詢中建立單結果集,提交一個事務的語句為____ 。
6、SQLServer的兩種授權模式分別為___和___。
7、有一個資料表其一行有5KB,有10000行資料,那麼我們至少需要__M的資料庫空間。
8、資料完整性分為__,__,__.
9、每個允許有_個簇索引,_索引是SQLServer預設選擇。
10、可以使用__關鍵字顯示未加密預存程序資訊,執行預存程序的關鍵字是_,統計列平均值的彙總函式為____,修改對象的關鍵字為_,刪除對象的關鍵字為___。
11、____資料庫儲存所有的暫存資料表和暫存預存程序。
三、簡答題(15分)
1、請簡述一下第二範式(3分)
2、請簡述UPDATE 觸發器工作原理(3分)
3、強制參考完整性時,簡述SQL Server 禁止使用者進行的操作(3分)
4、簡述相互關聯的子查詢的步驟(3分)
5、簡述使用索引和不使用索引的理由(3分)
上機題(25分)
一、(12分)問題描述:
已知關係模式:
S (SNO,SNAME) 學生關係。SNO 為學號,SNAME 為姓名
C (CNO,CNAME,CTEACHER) 課程關係。CNO 為課程號,CNAME 為課程名,CTEACHER 為任課教師
SC(SNO,CNO,SCGRADE) 選課關係。SCGRADE 為成績
找出沒有選修過“李明”老師講授課程的所有學生姓名(4分)
列出有二門以上(含兩門)不及格課程的學生姓名及其平均成績(4分)
- 列出既學過“1”號課程,又學過“2”號課程的所有學生姓名(4分)
二、定義一個十進位轉換成2進位的純量涵式。(4分)
三、活期存款中,“儲戶”通過“存取款單”和“儲蓄所”發生聯絡。假定儲戶包括:帳號,姓名,電話,地址,存款額;“儲蓄所”包括:儲蓄所編號,名稱,電話,地址(假定一個儲戶可以在不同得儲蓄所存取款)
1、寫出設計以上表格的語句(4分)
2、建立一個觸發器TR1完成下面內容:
當向“存取款單”表中插入資料時,如果存取標誌=1則應該更改儲戶表讓存款額加上存取金額,如果存取標誌=0則應該更改儲戶表讓存款額減去存取金額,如果餘額不足顯示餘額不足錯誤。(5分)
sql server考試題