一、實驗目標
1.掌握select語句的基本語法。
2.掌握select簡單查詢。
3.掌握sql中的關鍵字查詢。
首頁建立乙個scstc資料庫並建立資料表,並每個表至少錄入5條初始資料。
1, 建立student表
create table student
( sno char(8) primary key, --學號(主鍵)
sname char (8) not null, --姓名
*** char(2), --性別
native char(20), --籍貫
birthday smalldatetime, --出生日期
dno char(6), --所在院系編號(外來鍵)
spno char(8), --***碼(外來鍵)
classno char(4), --班級號
entime smalldatetime, --入校時間
home varchar (40), --家庭住址
tel varchar (40) --聯絡**
)二、實驗要求
select 語法基本句型:select 列名 from 表名
1,查詢student表中所有記錄。
select*from student
2,查詢student表中所有學生的學號、姓名、性別情況。
select sno,sname,*** from student
3,查詢student表中所有學生的sname\***\ home列名,要求各列名分別用漢字別名顯示。
select sname as 姓名,*** as 性別,home as 家庭位址 from student
4,查詢student表中性別為男的學生所有資訊。
select*from student where ***='男'
5,查詢student表中性別為男且籍貫為四川省的學生資訊。
select*from student where ***='男' and home='四川省'
6,查詢student表**生日期為2023年後出生的學生資訊。
select*from student where birthday>'1992-01-02'
7,查詢student表中姓名為「張三」同學的學號,姓名,性別,入校時間,班級號資訊。
select sno,***,entime,classno from student where sname='張三'
8,查詢student表中學生的籍貫情況,要求不重複。
select distinct native from student
9,查詢student表中學生前十位同學的情況。
select top 10* from student
10,查詢student表中學生出生日期最大的前十位同學的情況。
select top 10 birthday from student order by birthday desc
11,查詢student表中學生出生日期最小的前十位同學的情況。
select top 10 birthday from student order by birthday asc
12,查詢student表**生日期在2023年至2023年間出生的學生情況。(用兩種寫法實現)
select birthday from student where birthday between 1990 and 1996
select birthday from student where birthday>1990 and birthday<1996
13,查詢student表中籍貫為四川省、雲南省、貴州省的學生情況。
select home from student where home in('四川省','雲南省','貴州省')
14,查詢student表中所有姓」張」的學生姓名、性別、家庭住址、聯絡**。
select sname,***,home,tel from student where sname like'[張]%'
13,查詢student表中所有姓」張」且只包含兩字名字的學生資訊。
select sname from student where sname like '張_'
15,查詢student表中姓名的第二個字為「玉」字的所有學生資訊。
select sname from student where sname like '_玉%'
16,查詢student表中姓名的第三個字為「玉」字的所有學生資訊。
select sname from student where sname like '__玉%'
17,查詢student表中聯絡**中區號為「028」開頭的學生學號、姓名、聯絡**、家庭住址資訊。
select sno,sname,home,tel from student where tel like'[028]%'
18,查詢student表中籍貫不為四川省、貴州省的學生情況。
19,查詢student表中姓「張」和姓「李」的學生情況。
select*from student where sname like'[張李]%'
注意:寫出以上內容的語句,本次內容要求上交科代表,作為平時成績。
友情提示:將以上資料庫資料表分離出sql企業管理器,以備下次使用。
實驗四資料查詢 2
實驗四 教學管理系統 資料查詢 2 一 實驗目標 1 熟練掌握各種子查詢的方法使用 2 掌握檢視的建立方法 二 實驗內容 1 用子查詢實現學生成績資訊查詢功能 實驗場景 學期結束時班主任通過下述子任務 的查詢結果,將有不及格課程的學生成績單郵寄到學生家中,通知準備開學後補考。而教務處負責成績管理的老...
百萬資料查詢優化技巧三十則
20 的 用去了80 的時間,這是程式設計中的乙個著名定律,在資料庫應用程式中也同樣如此。我們的優化要抓住關鍵問題,對於資料庫應用程式來說,重點在於sql的執行效率。查詢優化的重點環節是使得資料庫伺服器少從磁碟中讀資料以及順序讀頁而不是非順序讀頁。百萬資料查詢優化技巧三十則 1.對查詢進行優化,應盡...
資料結構查詢排序實驗
實驗五 查詢和排序 班級 b09513 學號 200940 姓名 一 實驗目的 1 掌握查詢的不同方法,並能用高階語言實現查詢演算法。2 熟練掌握順序表和有序表的順序查詢和二分查詢方法。3 掌握排序的不同方法,並能用高階語言實現排序演算法。4 熟練掌握順序表的選擇排序 氣泡排序和直接插入排序演算法的...