sql server考試題

1、選擇題(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列輸入的數值,容許爲空。java

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
'sql

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 employeeapp

8)在sql server 2000中,關於數據庫說法錯誤的是()。(選擇一項)
a)數據庫在磁盤上默認的存儲位置是:SQL Server安裝路徑/Microsoft SQL Server/MSSQL/Data
b)一個數據庫至少應包含一個數據庫文件(.mdf)和一個事務日誌文件(.ldf)
c)只有當數據庫中不存在數據的狀況下,才能夠進行數據庫的收縮操做。
d)能夠經過從A機器拷貝數據庫文件和事務日誌文件至B機器,而後經過在B機器上執行相應的附加數據庫操做,實現數據庫從A機器到B機器的複製。ide

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 <=60this

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 typescala

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.

2、填空題(每空一分共25分)
一、關係R是1NF,當且僅當全部的基礎域僅包含____
二、主關鍵字應該具備____性,__性,__性。
三、關係R是3NF,當且僅當R是2NF,而且全部非PK屬性都是__於PK。
四、Transact-SQL 語言包含語言,語言,語言。
五、消除列重複的關鍵字是
,使用_操做符從多個查詢中建立單結果集,提交一個事務的語句爲____
六、SQLServer的兩種受權模式分別爲___
___
七、有一個數據表其一行有5KB,有10000行數據,那麼咱們至少須要__M的數據庫空間。
八、數據完整性分爲__,__,__.
九、每一個容許有_
個簇索引,_索引是SQLServer默認選擇。
十、可使用__
關鍵字顯示未加密存儲過程信息,執行存儲過程的關鍵字是_
,統計列平均值的聚合函數爲____,修改對象的關鍵字爲_,刪除對象的關鍵字爲___
十一、____數據庫保存全部的臨時表和臨時存儲過程。

3、簡答題(15分)
一、請簡述一下第二範式(3分)
二、請簡述UPDATE 觸發器工做原理(3分)
三、強制引用完整性時,簡述SQL Server 禁止用戶進行的操做(3分)
四、簡述相關子查詢的步驟(3分)
五、簡述使用索引和不使用索引的理由(3分)
上機題(25分)
1、(12分)問題描述:
已知關係模式:
S (SNO,SNAME) 學生關係。SNO 爲學號,SNAME 爲姓名
C (CNO,CNAME,CTEACHER) 課程關係。CNO 爲課程號,CNAME 爲課程名,CTEACHER 爲任課教師
SC(SNO,CNO,SCGRADE) 選課關係。SCGRADE 爲成績

  1. 找出沒有選修過「李明」老師講授課程的全部學生姓名(4分)

  2. 列出有二門以上(含兩門)不及格課程的學生姓名及其平均成績(4分)

  3. 列出既學過「1」號課程,又學過「2」號課程的全部學生姓名(4分)2、定義一個十進制轉換成2進制的標量函數。(4分)3、活期存款中,「儲戶」經過「存取款單」和「儲蓄所」發生聯繫。假定儲戶包括:帳號,姓名,電話,地址,存款額;「儲蓄所」包括:儲蓄所編號,名稱,電話,地址(假定一個儲戶能夠在不一樣得儲蓄所存取款)一、寫出設計以上表格的語句(4分)二、建立一個觸發器TR1完成下面內容:當向「存取款單」表中插入數據時,若是存取標誌=1則應該更改儲戶表讓存款額加上存取金額,若是存取標誌=0則應該更改儲戶表讓存款額減去存取金額,若是餘額不足顯示餘額不足錯誤。(5分)
相關文章
相關標籤/搜索