1.DISTINCT、top
2.convert
3.查詢、更新、管理
4.主鍵、外鍵
5.ROLLBACK TRAN、COMMIT TRAN
6.sp_renamedb
8.identity
9.插入數據的列數必須和表中列數相等
10.空
12.truncate
14.原子性、一致性、隔離性、永久性
16.count、avg、len、substring
17.cast
18.windows
19.物理數據表
20.<>、!=
㈡ java面試SQL題,跪求大神解答
SELECTTOP10u.name,u.age,allin=isnull((SELECTsum(t.number*p.buyprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='BUY'),0),
allout=isnull((SELECTsum(t.number*p.saleprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='SALE'),0)
,
realin=(isnull((SELECTsum(t.number*p.buyprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='BUY'),0)-isnull((SELECTsum(t.number*p.saleprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='SALE'),0))
FROMTEST_USERu
ORDERBY(isnull((SELECTsum(t.number*p.buyprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='BUY'),0)-isnull((SELECTsum(t.number*p.saleprice)FROMTEST_PRODECTp,TEST_TREEDt
WHEREp.type=t.ptypeANDt.uid=u.useridANDt.BUY_OR_SALE='SALE'),0))DESC
第2題答案
經過測試無誤
㈢ SQL測試題(註:最佳答案必須能在MySQL下運行)
/*
閑著沒事,瞅瞅網路上的問題,今天天晚了,先解決一個,另一個明兒個再說了!
第二道題也算已經搞定了!
環境 : mysql Ver 14.12 Distrib 5.0.45, for Win32 (ia32)
參考 :
exist與in 的區別
http://blog.csdn.net/change888/archive/2008/03/31/2232778.aspx
*/
/*********************************問題 1 **************************************/
drop table if exists s;
create table if not exists s (s varchar(32), sn varchar(32), sd varchar(32),
sa int);
insert into s values ('s1', '朱', '開發本部', 23);
insert into s values ('s2', '牛', '人事部', 25);
insert into s values ('s3', '楊', '財務部', 26);
insert into s values ('s4', '馬', '開發本部', 22);
insert into s values ('s5', '呂', '人事部', 27);
insert into s values ('s6', '於', '開發本部', 28);
insert into s values ('s7', '侯', '開發本部', 28);
drop table if exists c;
create table if not exists c (c varchar(32), cn varchar(32));
insert into c values ('c1', '軟體工程');
insert into c values ('c2', '計算機技術與科學');
insert into c values ('c3', '車輛工程');
drop table if exists sc;
create table if not exists sc (s varchar(32), c varchar(32));
insert into sc values ('s1', 'c1');
insert into sc values ('s1', 'c2');
insert into sc values ('s1', 'c3');
insert into sc values ('s2', 'c1');
insert into sc values ('s2', 'c3');
insert into sc values ('s3', 'c2');
insert into sc values ('s4', 'c2');
insert into sc values ('s4', 'c3');
insert into sc values ('s5', 'c1');
insert into sc values ('s6', 'c3');
/* 1. 查詢選修課程名稱為 「軟體工程」 的學員學號和姓名 */
select s.s '學號', s.sn '姓名' from s where s.s in
(select sc.s from sc where sc.c in
(select c.c from c where c.cn = '軟體工程'));
/* 2. 查詢選修課程編號為 「C2」 的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where s.s in
(select sc.s from sc where sc.c = 'C2');
/* 3. 查詢選修課程編號 不 為 「C2」 的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where
s.s not in (select sc.s from sc where sc.c = 'C2')
and
s.s in (select sc.s from sc);
/* 4. 查詢選修全部課程的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where
(select count(DISTINCT sc.c) from sc where sc.s = s.s)
=
(select count(DISTINCT c.c) from c );
/* 5. 查詢選修了課程的學員人數 */
select count(DISTINCT sc.s) '人數' from sc;
/* 6. 查詢選修課程 >= 2 門的學員學號和所屬單位 (不得不用 CASE 語句了)*/
select s.sn '姓名', s.sd '所屬單位' from s where s.s in
(select CASE WHEN count(DISTINCT sc.c) >=2 THEN sc.s END from sc group by sc.s );
/* 運行結果
------------------------------------1
+------+------+
| 學號 | 姓名 |
+------+------+
| s1 | 朱 |
| s2 | 牛 |
| s5 | 呂 |
+------+------+
------------------------------------2
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
| 楊 | 財務部 |
| 馬 | 開發本部 |
+------+----------+
------------------------------------3
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 牛 | 人事部 |
| 呂 | 人事部 |
| 於 | 開發本部 |
+------+----------+
------------------------------------4
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
+------+----------+
------------------------------------5
+------+
| 人數 |
+------+
| 6 |
+------+
------------------------------------6
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
| 牛 | 人事部 |
| 馬 | 開發本部 |
+------+----------+
*/
/*********************************問題 2 **************************************/
drop table if exists s ;
create table if not exists s ( sno varchar(32), sname varchar(32));
insert into s values ('s1', '朱');
insert into s values ('s2', '牛');
insert into s values ('s3', '楊');
insert into s values ('s4', '馬');
insert into s values ('s5', '呂');
insert into s values ('s6', '於');
insert into s values ('s7', '侯');
drop table if exists c;
create table if not exists c ( cno varchar(32), cname varchar(32),
cteacher varchar(32));
insert into c values ('c1', '數學', '張');
insert into c values ('c2', '日語', '李'); /*假設李老師同時教授日語和英語*/
insert into c values ('c3', '英語', '李');
drop table if exists sc;
create table if not exists sc (sno varchar(32), cno varchar(32),
scgrade double);
insert into sc values ('s1', 'c1', 75);
insert into sc values ('s1', 'c2', 70);
insert into sc values ('s1', 'c3', 80);
insert into sc values ('s2', 'c1', 50);
insert into sc values ('s2', 'c3', 40);
insert into sc values ('s3', 'c1', 50);
insert into sc values ('s3', 'c2', 60);
insert into sc values ('s4', 'c1', 90);
insert into sc values ('s4', 'c2', 40);
insert into sc values ('s4', 'c3', 20);
insert into sc values ('s5', 'c1', 80);
insert into sc values ('s6', 'c1', 85);
/* 1. 沒有 選 修過「李」老師講授課程的所有學生姓名 */
select s.sname '姓名' from s where s.sno not in
(select sc.sno from sc where sc.cno in
(select c.cno from c where c.cteacher = '李'));
/* 2. 列出有二門以上(含兩門)不及格課程的學生姓名及其平均成績 */
select s.sname '姓名', AVG(sc.scgrade) '平均成績' from s, sc
where s.sno = sc.sno
and
(select count(sc.sno) from sc where sc.sno = s.sno
and sc.scgrade < 60 ) >= 2
group by s.sno;
/* 3. 列出既學過「C1」號課程,又學過「C2」號課程的所有學生姓名 */
select s.sname '姓名' from s where s.sno in
(select t1.sno from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1' and t2.cno = 'c2');
/*或者*/
select s.sname '姓名' from s where s.sno in
(select sc.sno from sc where sc.cno = 'c1' and sc.sno in
(select t1.sno from sc t1 where t1.cno = 'c2'));
/* 4. 列出「C1」號課成績比「C2」號同學該門課成績高的所有學生的學號 */
select t1.sno '學號' from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1'
and t2.cno = 'c2' and t1.scgrade > t2.scgrade;
/* 5. 列出「C1」成績比「C2」成績高的學生的學號及其「C1」和「C2」的成績 */
select t1.sno '學號', t1.scgrade 'C1成績', t2.scgrade 'C2成績' from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1'
and t2.cno = 'c2' and t1.scgrade > t2.scgrade;
/* 運行結果
------------------------------------1
+------+
| 姓名 |
+------+
| 呂 |
| 於 |
| 侯 |
+------+
------------------------------------2
+------+----------+
| 姓名 | 平均成績 |
+------+----------+
| 牛 | 45 |
| 馬 | 50 |
+------+----------+
------------------------------------3
+------+
| 姓名 |
+------+
| 朱 |
| 楊 |
| 馬 |
+------+
------------------------------------4
+------+
| 學號 |
+------+
| s1 |
| s4 |
+------+
------------------------------------5
+------+--------+--------+
| 學號 | C1成績 | C2成績 |
+------+--------+--------+
| s1 | 75 | 70 |
| s4 | 90 | 40 |
+------+--------+--------+
*/
㈣ 求sql資料庫考試題答案
1.create database Readbook
on
(name=Readbook_data,filename='D:\server\Readbook_data.mdf',size=2mb,maxsize=10mb,filegrowth=1mb)
log on
(
name=Readbook_log,
filename='D:\server\Readbook_log.ldf',size=1mb,maxsize=5mb,filegrowth=1mb
)
go
2.use mybase
go
alter database mybase
add log file
(
name=Readbook2_log,
filename='D:\server\mybase2_log.ldf',size=2mb,maxsize=10mb,filegrowth=1mb
)
go
3.alter database mybase
remove file Readbook2_log
㈤ SQL server練習題,在線急等答案
**************
第一大題
**************
1. 求客戶ID為「張娟」所下的訂單中所包含的產品ID(10)
select distinct 產品ID from orders where 訂單ID in (select 訂單ID from procts where 客戶ID = '張娟');
2. 求客戶ID:要求這些客戶所下的訂單中產品ID有「51」的客戶ID(10)
select distinct 客戶ID from procts where 訂單ID in(select 訂單ID from orders where 產品ID = '51');
3. 求產品ID為「51」所在的訂單中所包含的所有的 產品ID(10)
select distinct 產品ID from orders where 訂單ID in( select 訂單ID from orders where 產品ID = '51');
4. 統計客戶ID為「張娟」所下的訂單中所包含的產品種類個數。(15)
select count(distinct 產品ID) from orders where 訂單ID in (select 訂單ID from procts where 客戶ID = '張娟');
5. 統計每個客戶所下的訂單中所包含的產品種類個數。(20)
select 客戶ID,sum((select count(distinct 產品ID) from orders where 訂單ID = procts.訂單ID)) as 產品種類個數 from procts group by 客戶ID;
6. 創建一個名稱」proc_ClientIDByOrderID」為存儲過程:要求給出客戶ID,返回該該客戶ID所下的訂單中產品ID(15)
create proc proc_ClientIDByOrderID(@customer_id varchar(50))
as
declare @str_sql varchar(1000);
set @str_sql = 'select distinct 產品ID from orders where 訂單ID in (select 訂單ID from procts where 客戶ID = ' + @customer_id + ')';
exec(@str_sql);
7. 創建一個名稱為Field_Rule的規則,並將其綁定到訂單表Orders的訂單ID上,規定取值只能五個數字(10)
create rule Field_Rule
as
@id like '[0-9][0-9][0-9][0-9][0-9]'
exec sp_bindrule 'Field_Rule','Orders.訂單ID';
**************
第二大題
**************
1. 求名稱為「編輯」的菜單所對應的子菜單項(10)
select distinct 菜單名稱 from Menu where 上級菜單編碼 in( select 菜單編碼 from Menu where 菜單名稱 = '編輯');
2. 求名稱為「保存」的子菜單項所在的上級菜單名稱(10)
select distinct 菜單名稱 from Menu where 菜單編碼 in( select 上級菜單編碼 from Menu where 菜單名稱 = '保存');
3. 求角色名稱為「一般用戶」的角色所能操作的菜單名稱(10)
select distinct 菜單名稱 from Menu where 許可權編碼 in( select 許可權編碼 from Role where 角色名稱 = '一般用戶');
4. 統計名稱為「一般用戶」的角色所能操作的菜單項數(15)
select count(distinct 菜單名稱) from Menu where 許可權編碼 in( select 許可權編碼 from Role where 角色名稱 = '一般用戶');
5. 統計每個角色所能操作的菜單項數(20)
select 角色名稱,sum((select count(distinct 菜單名稱) from Menu where 許可權編碼 =Role.許可權編碼)) as 菜單項數 from Role group by 角色名稱;
6. 創建一個名稱為存儲過程:要求給出角色名稱,返回該該角色所能操作的菜單名稱。(15)
create proc Role_count_proc(@Role_name varchar(50))
as
declare @str_sql varchar(1000);
set @str_sql = 'select distinct 菜單名稱 from Menu where 許可權編碼 in( select 許可權編碼 from Role where 角色名稱 = '+ @Role_name +')';
exec(@str_sql);
7. 創建一個名稱為Field_Rule的規則,並將其綁定到菜單表Menu上的上級菜單編碼列上,規定取值只能是兩個數字,或者是四個數字,或者為null
create rule Field_Rule
as
@id like '[0-9][0-9]' or @id like '[0-9][0-9]' or @id is null;
exec sp_bindrule 'Field_Rule','Menu.上級菜單編碼'
---
以上,希望對你有所幫助。
㈥ 哪位大俠可以提供一些mysql資料庫的題庫,一定要帶答案的!將感激不盡!!
一、不定項選擇題(共40題,每小題2.5分,總分100分)
1. 資料庫管理系統的發展歷經了如下那些模型階段( ACDE )
A. 層次模型 B. 結構模型 C. 關系模型
D. 網狀模型 E.對象模型
2. 關系型資料庫的核心單元是( B )
A. 對象 B. 表
C. 行 D. 列
3. 對於關系型資料庫來說,表之間存在下面那些關系( ABC )
A. 一對一關系 B. 一對多關系
C. 多對多關系 D. 繼承關系
4. 在SQL中,下面對於數據定義語言(DDL)描述正確的是( D )。
A. DDL關心的是資料庫中的數據 B. 完成數據的增、刪、改、查操作
C. 控制對資料庫的訪問 D. 定義資料庫的結構
5. MySQL是一種( C )資料庫管理系統。
A. 層次型 B. 網路型 C. 關系型 D. 對象型
6. SQL中,下列操作有語法錯誤的是( B )
A. AGE IS NOT NULL B. NOT(AGE IS NULL)
C. SNAME=『王五』 D. SNAME=『王%』
7. SQL中,下列關於創建、管理資料庫的操作語句不正確的是( CDE )
A. CREATE DATABASE Instant B. USE Instant C. NEW DATABASE Instant
D. Connection Instant E. Delete DATEBASE Instant
8. 在MySQL中,不存在的數據類型是( F )。
A. INT B. TEXT C. DECIMAL
D. VARCHAR E. DATETIME F. VARCHAR2
9. 在MySQL中,下列關於創建資料庫表的描述正確的是( C )。
A. 在創建表時必須設定列的約束
B. 在刪除表的時候通過外鍵約束連接在一起的表會被一同刪除
C. 在創建表時必須設置列類型
D. 通過CREATE TABLE new_t SELECT * FROM old_t復製表的同時,表的約束能夠一起被復制到新表中
10. 根據數據完整性實施的方法,可以將其分為( ACDF )
A. 實體完整性 B. 表完整性 C.域完整性
D. 引用完整性 E. 記錄完整性 F.用戶自定義完整性
11. 下面關於域完整性的方法,不正確的是( A )。
A. 主鍵約束 B. 外鍵約束 C.檢查約束
D. 非空約束 E. 默認值
12. 下面關於創建和管理索引正確的描述是( C )。
A. 創建索引是為了便於全表掃描
B. 索引會加快DELETE、UPDATE和INSERT語句的執行速度
C. 索引被用於快速找到想要的記錄
D. 大量使用索引可以提高資料庫的整體性能
13. SQL中,「AGE IN(20,22)」的語義是( D )。
A. AGE<=22 AND AGE >=20 B. AGE <22 AND AGE >20
C. AGE =20 AND AGE =22 D. AGE =20 OR AGE =22
14. 有一個關系:學生(學號,姓名,系別),規定學號的值域是8個數字組成的字元串,這一規則屬於( C )
A. 實體完整性約束 B. 參照完整性約束
C. 用戶自定義完整性約束 D. 關鍵字完整性約束
15. 下面SQL是來源於考試成績表t_exam:學號stuId、科目編號subId、成績score,考試日期:ex_date。有以下sql,它表示的意思是:( B )
Select stu_id,subId,count(*) as x
From t_exam
Where ex_date=』2008-08-08』
Group stu_id,subId
Having count(*)>1
Order by x desc
A. 找出』2008-08-08』這天某科考試2次及以上的學生記錄
B. 找出』2008-08-08』這天,某科考試2次及以上的學生記錄,考試次數多的放在前面
C. 找出』2008-08-08』這天,某科考試2次及以上的學生記錄,考試次數少的放在前面
D. 根據學號和學科分組,找出每個人考試科數,最後考試次數多的放在前面
16. EMP表如下所示,下面哪些SQL語句的返回值為3:( BD )
EMP
雇員號 雇員名 部門號 工資
001 張山 022000
010 王宏達01 1200
056 馬林生02 1000
101 趙敏 04
A. select count(*) from emp
B. select count(distinct 部門號) from emp
C. select count(*) from emp group by 雇員號
D. select count(工資) from emp
17. 下面那一項不是SELECT語句對數據的操作:( D )
A. 投影 B. 聯接 C. 並 D. 級聯
18. 下面關於SQL數據查詢操作描述正確的有:( ABD )
A. 投影操作是選擇對表中的哪些列進行查詢操作
B. 使用DISTINCT關鍵字可以過濾查詢中重復的記錄
C. 在模糊查詢中,通配符「%」表示匹配單個字元,而「_」表示匹配零個或多個字元
D. 在MySQL中使用LIMIT關鍵字限制從資料庫中返回記錄的行數
19. 在SQL語言中,條件「BETWEEN 20 AND 30」表示年齡在20到30之間,且( A )。
A. 包括20歲和30歲 B. 不包括20歲和30歲
C. 包括20歲,不包括30歲 D. 不包括20歲,包括30歲
20. SQL語言中,刪除EMP表中全部數據的命令正確的是( C )。
A. delete * from emp B. drop table emp
C. truncate table emp D. 沒有正確答案
21. 有關索引的說法錯誤的是( AD )
A. 索引的目的是為增加數據操作的速度
B. 索引是資料庫內部使用的對象
C. 索引建立得太多,會降低數據增加刪除修改速度
D. 只能為一個欄位建立索引
22. 下列哪個關鍵字在Select語句中表示所有列( A )
A. * B. ALL C. DESC D. DISTINCT
23. 在表中設置外鍵實現的是哪一類數據完整性( B )
A. 實體完整性 B. 引用完整性
C. 用戶定義的完整性 D. 實體完整性、引用完整性和用戶定義的完整性
24. 下面正確表示Employees表中有多少非NULL的Region列的SQL語句是( B )
A. SELECT count(* ) from Employees
B. SELECT count(ALL Region) from Employees
C. SELECT count(Distinct Region) from Employees
D. SELECT sum(ALL Region) from Employees
25. 下面可以通過聚合函數的結果來過濾查詢結果集的SQL子句是( C )
A. WHERE子句 B. GROUP BY子句
C. HAVING 子句 D. ORDER BY子句
26. t_score(stu_id,sub_id,score),即成績表(學號,科目編號,成績)。學生如果某科沒有考試,則該科成績錄入null。能夠獲取各位學生的平均成績的選項是( A )
A. select avg(nvl(socre,0)) from score group by stu_id
B. select stu_id,avg(sorce) from score
C. select stu_id,avg(score) from score
D. select stu_id,sum(score)/count(score) from score
27. 若要求查找S表中,姓名的第一個字為'王'的學生學號和姓名。下面列出的SQL語句中,哪個是正確的( B )
A. SELECT Sno,SNAME FROM S WHERE SNAME=′王%′
B. SELECT Sno,SNAME FROM S WHERE SNAME LIKE′王%′
C. SELECT Sno,SNAME FROM S WHERE SNAME LIKE′王_′
D. 全部
28. 若要求「查詢選修了3門以上課程的學生的學生號」,正確的SQL語句是( B )
A. SELECT Sno FROM SC GROUP BY Sno WHERE COUNT(*)> 3
B. SELECT Sno FROM SC GROUP BY Sno HAVING( COUNT(*)> 3)
C. SELECT Sno FROM SC ORDER BY Sno WHERE COUNT(*)> 3
D. SELECT Sno FROM SC ORDER BY Sno HAVING COUNT(*)>= 3
29. 對下面的查詢語句描述正確的是( D )
Select StudentID,Name,
(select count(*) from StudentExam
where StudentExam.StudentID = Student.StudentID) as ExamsTaken
from Student
order by ExamsTaken desc
A. 從Student表中查找StudentID和Name,並按照升序排列
B. 從Student表中查找StudentID和Name,並按照降序排列
C. 從Student表中查找StudentID、Name和考試次數
D. 從Student表中查找StudentID、Name,並從StudentExam表中查找與StudentID一致的學生考試次數,並按照降序排列
30. 下面題基於學生-課程資料庫中的三個基本表:
學生信息表:s(sno, sname, sex, age, dept) 主鍵為sno
課程信息表:c(cno, cname, teacher) 主鍵為cno
學生選課信息表:sc(sno, cno, grade) 主鍵為(sno, cno)
「從學生選課信息表中找出無成績的學生信息」的SQL語句是( C d )
A.
SELECT * FROM sc WHERE grade=NULL
B.
SELECT * FROM sc WHERE grade IS 『 』
C.
SELECT * FROM sc WHERE grade IS NULL
D.
SELECT * FROM sc WHERE grade =『 』
31. 當子查詢返回多行時,可以採用的解決辦法是( C )。
A. 使用聚合函數 B. Where條件判斷
C. 使用IN運算符 D. 使用Group by進行分組
32. 下面關於在子查詢中使用運算符描述不正確的是( D )。
A. 使用IN運算符用於查找欄位值屬於某一組值的行
B. 使用Exists運算符用於測試子查詢是否返回行,如果返回其值就為真
C. 使用ALL運算符用於測試子查詢結果集的所有行是否滿足指定的條件
D. 使用Any運算符用於測試子查詢結果集中的一行或多行不滿足指定的條件
33. 下面關於組合查詢描述不正確的是( D )。
A. 從一個表中獲取的數據必須和其它表中的數據具有相同的列數
B. 兩個表中相對應的列必須具有相同的數據類型
C. UNION的結果集列名與第一個SELECT語句的結果集中的列名相同
D. UNION的結果集列名與第二個SELECT語句的結果集中的列名相同
E. UNION ALL運算符返回每個數據集的所有成員
34. 下面關於聯接的描述正確的是( A )。
A. 內聯接使用比較運算符根據每個表共有的列值來匹配兩個表中的行
B. 左外聯接結果集包含從右邊的表返回的所有行
C. 右外聯接結果集包含從左邊的表返回的所有行
D. 全外聯接返回左表和右表中的所有匹配的行
35. 下面關於資料庫設計過程正確的順序描述是( C )。
A. 需求收集和分析、邏輯設計、物理設計、概念設計
B. 概念設計、需求收集和分析、邏輯設計、物理設計
C. 需求收集和分析、概念設計、邏輯設計、物理設計
D. 需求收集和分析、概念設計、物理設計、邏輯設計
36. ER圖屬於下面哪一種資料庫設計模型( B )。
A. 物理數據模型
B. 概念數據模型
C. 邏輯數據模型
D. 需求模型
37. 非主鍵必須完全依賴於主鍵列,這屬於下列範式的內容( BC )
A. 1NF B. 2NF C. 3NF D. 都沒有的
38. 如果一個欄位的數據必須來源另一個表的主鍵,那麼要在這個欄位上建立( B )。
A. PK(主鍵) B. FK(外鍵) C. UK(唯一鍵) D. 復合主鍵
39. 根據三個範式的定義,下面哪個選項的設計是正確的( C )
職工編號 姓名 工種 車間 車間主任
1001 李寧 車工 一車間 周傑
1002 王海 銑工 一車間 周傑
1003 趙亮 鉗工 二車間 吳明
1001 李寧 鉗工 二車間 吳明
A. 員工表、工種表、車間表
B. 員工表、工種表、車間表、車間主任表
C. 員工表、工種表、車間表、員工工種表、員工車間表
D. 以上設計均不正確
40. 下列說法中,哪些是正確的( BD )
A. RDBMS是資料庫管理系統的簡稱
B. 各行記錄都不能重復,是第二範式要求的
C. 在資料庫設計中一定要滿足第三範式
D. 索引越多,查詢越快,數據更新越慢
㈦ SQL資料庫試題求解
------------------------------------------------------
create table students(st_id varchar(20),st_name varchar(50),sex varchar(10))
insert into students(st_id,st_name,sex)
select 'st001','張傑', '男' union all
select 'st002', '公孫燕飛' ,'男' union all
select 'st003', '王楠', '女' union all
select 'st004', '王偉', '男' union all
select 'st005','李燕紋', '女' union all
select 'st006', '孫武' ,'男'
select *
from students
create table teachers(t_id varchar(20),t_name varchar(50),t_lesson varchar(50))
insert into teachers
select 't001', '張老師' ,'數學' union all
select 't002', '李老師', '英語'
delete from results
create table results(r_id varchar(20),r_fenshu int,r_stid varchar(50),r_tid varchar(50))
insert into results
select 'r001','90', 'st001', 't002' union all
select 'r002', '68', 'st005', 't001' union all
select 'r003', '92', 'st003' ,'t001' union all
select 'r004', '82', 'st006', 't002' union all
select 'r005', '70', 'st002', 't002' union all
select 'r006', '86', 'st002', 't001' union all
select 'r007', '57', 'st003', 't002' union all
select 'r008', '76', 'st006', 't001' union all
select 'r009', '55', 'st001', 't001' union all
select 'r010', '77', 'st004', 't002' union all
select 'r011', '58', 'st005', 't002'
----------------------------------------------------------
1.
select st_id
from students
where st_name = '王偉'
2.select st_id,st_name
from students
where st_name like '__燕%'
3 select st_name,len(st_name) as 名字長度
from students
where sex ='男'
4 select min(r_fenshu) as 最低分數
from teachers t inner join results r on t.t_id =r.r_tid
where t_lesson ='數學' --這個是不考慮成績中有null值的
5 select s.st_id as 學生編號,r_fenshu as分數,r_tid as 課目號
from students s inner join results r on s.st_id =r.r_stid
where s.sex='女'
--如果還要課目的名稱的話請用下面的
select s.st_id as 學生編號,r.r_fenshu as 分數,r.r_tid as 課目號,t.t_lesson as 課目名稱
from students s inner join results r on s.st_id =r.r_stid
inner join teachers t on r.r_tid = t.t_id
where s.sex='女'
6 select avg(r.r_fenshu)
from results r inner join teachers t on r.r_tid = t.t_id
where t.t_lesson='英語'
7.select *
from students s inner join results r on s.st_id =r.r_stid
inner join teachers t on r.r_tid = t.t_id
where s.st_id in (select top 2 st_id from students order by st_id desc)
order by s.st_id desc
8 select sum(r.r_fenshu) as 總分
from results r inner join students s on r.r_stid =s.st_id
where s.st_name = '王楠'
9.select distinct s.st_id,s.st_name
from students s inner join results r on s.st_id = r.r_stid
where st_id not in (select r_stid from results where r_fenshu<60) and st_id not in (select r_stid from results where r_fenshu >=90)
10 update results
set r_fenshu = r_fenshu + 10
--如果分數不可能大於100請用這句 set r_fenshu = case when r_fenshu + 10 <=100 then r_fenshu + 10 else 100 end
where r_stid in (select st_id from students where sex='女')
1 進階題
select t.t_name,count(*)
from students s,teachers t,results r
where r.r_tid = t.t_id
and s.st_id =r.r_stid
and r.r_fenshu >= 60
and t.t_id in (select t_id from teachers where t_lesson='數學' )
--and t_lesson='數學'
group by t.t_name
2
select top 1 sum(r_fenshu) as 總分,t.t_lesson,t_id,t_name
from results r,teachers t
where r.r_tid = t.t_id
group by t.t_lesson,t_id,t_name
order by 總分 desc
3. delete from results where r_stid in (select r_stid from results group by r_stid having count(r_tid) = 1)
1 選做題
select d.name from sysobjects d where d.xtype='U'
2.select top 5 * from students order by newid()
㈧ 最高分求SQL Server試題,考試要用,急!
一、填空題
1、beautiful、我心中的太陽--(去掉了右邊的空格)
2、實體、域
3、視圖
4.13.4300、13.4570--(保留2位和三位小數,但總位數不變)
5、數據定義語言(DDL)、數據操作語言(DML)
6、網狀、關系、關系
7、二維表、屬性、元組
8、一對一、一對多、多對多
9、%、_
二、選擇題
1、C
2、B
3、A
4、A
5、C
6、D
7、A
8、C
9、D
10、B
11、A
12、A
13、B
14、B
15、B
三、判斷題
1、√
2、ⅹ
3、ⅹ----會取整(12)
4、ⅹ
5、ⅹ--物極必反,多了存儲數據時會消耗較多系統資源
6、ⅹ--連接、投影結果是不一樣的
7、ⅹ--視圖上可以創建觸發器,但與表功能不相同
8、ⅹ
9、√
10、√
四、簡答題
(一)
區別:
1、視圖是已經編譯好的sql語句。而表不是
2、視圖沒有實際的物理記錄。而表有。
3、表是內容,視圖是窗口
4、表只用物理空間而視圖不佔用物理空間,視圖只是邏輯概念的存在,表可以及時四對它進行修改,但視圖只能有創建的語句來修改
5、表是內模式,試圖是外模式
6、視圖是查看數據表的一種方法,可以查詢數據表中某些欄位構成的數據,只是一些SQL語句的集合。從安全的角度說,視圖可以不給用戶接觸數據表,從而不知道表結構。
7、表屬於全局模式中的表,是實表;視圖屬於局部模式的表,是虛表。
8、視圖的建立和刪除隻影響視圖本身,不影響對應的基本表。
視圖優點:1、聚焦特定的數據。
2、簡化數據操作
3、定製用戶數據
4、對重構資料庫提供了一定程度的邏輯獨立性
5、合並分離的數據
6、屏蔽資料庫的復雜性
7、簡化用戶許可權的管理
8、便於數據的共享
(二)
含義:
存儲過程(Stored Procere)是一組為了完成特定功能的SQL語句集,經編譯後存儲在資料庫中。用戶通過指定存儲過程的名字並給出參數(如果該存儲過程帶有參數)來執行它。存儲過程是資料庫中的一個重要對象,任何一個設計良好的資料庫應用程序都應該用到存儲過程。
語法:
CREATE PROCEDURE [擁有者.]存儲過程名[;程序編號]
[(參數#1,…參數#1024)]
[WITH
{RECOMPILE | ENCRYPTION | RECOMPILE, ENCRYPTION}
]
[FOR REPLICATION]
AS 程序行
㈨ sql資料庫考試題及答案怎麼寫
buttonRemove.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
Language language = (Language)selection.getFirstElement();
if(language == null) {
System.out.println("Please select a language first.");
return;
}