------------------------------------------------------
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()
B. 求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
C. SQL多項選擇題,急求答案,最好有解析
1.答案A,D,E DESC是降序,省略ASC和DESC,默認為升序。
2.答案A,C,D,E 創建視圖時不允許在所用SELECT語句中使用ORDER BY、COMPUTE子句
3.C,D,E 執行存儲過程時可用WITH RECOMPLE選項進行重新編譯;只有當執行存儲過程的語句是批處理中的第一個語句,才可以直接通過名稱來調用存儲過程
4.C,E 使用SQL Server Management Studio不能運行命令行實用程序sqlcmd
5.C,D,F 一個局部變數只能在一個語句批中使用,使用SET語句只能對一個局部變數賦值,剛定義的局部變數的初值為空值
6.B 用戶定義函數可以有輸入參數和返回值
D. SQL資料庫的設計題,T-SQL語言。高分求解答!
1.
use scd
go
create default df_年齡 as '18'
sp_bindefault 'df_年齡','student.年齡'
2.
use scd
go
alter table class
with nocheck /*現有數據不強制這個約束*/
add constraint ck_入學年份
check(入學年份>=2008) /*你的提法「是否」有問題,到底是約束使其小於2008,還是約束使其大於等於2008,這句是指約束使入學年份>=2008,如果輸入的值<2008就違反了約束*/
E. 跪求sql程序設計題答案
1 select 姓名,部門名稱 from 部門,職工 where 部門.部門號=職工.部門號and 職務=「工程師」
2 update 工資級別 set 小時工資率=小時工資率*(1+5%) where 職務=「工程師」
3 select 職工號,sum(工時) from 施工 group by 職工號 having sum(工時)>40
4 select 部門名稱,電話號碼 from 部門,職工 where 部門.部門號=職工.部門號 and 姓名=「潘小光」
5 select 部門名稱,姓名,項目名稱 from 職工,部門,工程,施工 where 部門.部門號=職工.部門號 and 施工.項目號=工程.項目號
6 create sql view 酬金 as select 職工號,姓名,項目名稱,工時,小時工資率*工時 from 施工,職工,工程,工資級別 where 施工.項目號=工程.項目號 and
職工.職務=工資級別.職務 and 職工.職工號=施工.職工號
F. 高分求SQL題目答案
*****************
11、smallint是短整形 范圍:-32768到32767,它是SQL的數據類型。
12、SQL允許欄位為漢字
13、錯誤
14、正確
15、正確
*****************
3填空題
1、 100 和 C
2、beautiful 和 我心中的太陽
3、選擇, 投影、連接
4、6 和 8
5、13.4300 和 13.4570
*****************
4、設計題
問題參照下面網址的【五:設計題】:
http://www.sdwm.cn/xueyuan/jpk/sqljpk/lxtk/stk01.htm
答案參照下面網址【五】:
http://www.sdwm.cn/xueyuan/jpk/sqljpk/lxtk/stkda01.htm
*****************
補充說明:這個網站上的內容不粗的,學習SqlServer可以參照一下,希望你早日成為SqlServer大師。
以上,希望對你有所幫助。
G. SQL期末考試資料庫實訓相關問題
企業信息表:INT :id --序列型主鍵自動生成 。VARCHAR :NO--企業編碼,name--企業名稱,……其它附屬信息全部用VARCHAR自己定義把,例如聯系方式,地址,聯系人,所屬地區,備注等等,我只告訴你關鍵信息。
電價流水信息表:INT :id --序列型主鍵自動生成,企業信息表_ID外鍵,---企業信息表ID, DATE--日期,double:電量,電費,
電價單價表:INT :id --序列型主鍵自動生成,企業信息表_ID外鍵--企業信息表DI,
日期:年月,double:單價。這個你可以不寫,但是我們建模型這個基本都做。
2.,存儲過程頭你自己寫 ,監控電價單價表的添加和修改動作,自己照書操。
SQL: update 電價流水信息表 set 電價流水信息表.電費=電價流水信息表.電量*電價單價表.單價 from 電價單價表 where 電價流水信息表.企業信息表_ID=電價單價表. 企業信息表_ID and
格式化 電價流水信息表。日期為年月=電價單價表.日期
就是更新來源是電價單價表,通過2個關鍵詞更新,一個是企業信息ID,一個是格式化後的日期:年月
3.命名一個變數,查詢的時候sum 電量和電費,group by 企業名稱,where 裡面企業名稱=這個變數,
4.其實第三個會寫了 ,第四個 應該跟第三個一樣啊,只是定義了2個參數,一個是地區一個是年份,我告訴你分月統計的方法,查詢裡面sum的時候 格式化流水表的日期為 年月格式,GROUP BY 也要包含這個格式化,然後where裡面寫 格式化日期為年=參數的年
H. SQL期末考試題,來個大神幫解答一下
select fph from mz_brsf
whereje > 200;
2.select sum(je) from mz_brsf
where sfsj >= '2012-01-01'
and sfsj < '2012-02-01';
3.delete from mz_bfsf
where cfh is null;
4.update mz_bfsf
set substr(sfsj,1,4) =2013
where ks ='內科' ;
5. select ks, sum(je) from mz_bfsf
group by ks
having sum(je) >500;
6.select top 2 ys,sum(je)
from mz_bfsf
group by ys
order by sum(je) desc;
7.update a
set a.zc = b.zc
from mz_bfsf a,mz_brxx b
where a.ys = b.ys
I. sql資料庫設計題
1.select 學號,姓名 from 學生 where 班級='軟體041'
2.select * from 課程 where 課程名稱 like '%語言%'
3.select 學生.學號,姓名,班級 from 學生 where 學號 in(
select top 5 學號 from 選課 where 課程號 in(
select 課程號 from 課程 where 課程名稱='C語言'
) order by 成績 desc
)
4.select 班級,count(1) 學生人數 from 學生 group by 班級
5.select 學號 from 選課 where 課程號=(
select 課程號 from 課程 where 課程名稱='計算機應用基礎'
) 成績>(select 成績 from 選課 where 學號=(select 學號 from 學生 where 姓名='張三') and 課程號=(
select 課程號 from 課程 where 課程名稱='計算機應用基礎'
)
)