


版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
專業:計算機科學與技術 班級:1820544地點: D1003 時間:2020-10-30項目名稱:SQLServer課程環節: 數據庫原理與應用二〇二〇年十月PAGEPAGE8實驗一:在SQLServer中創建數據庫實驗環境 PC機+SQLServer 學號姓名 182054421李張一.實驗項目要求創建數據庫和查看數據庫屬性。創建表、確定表的主碼。查看和修改表結構。具體內容:SQL語句建立學生數據庫。查看學生數據庫的屬性,并進行修改,使之符合要求。使用SQL4構為;學生(學號,姓名,年齡,性別,所在系)課程(課程號,課程名,先行課,學分)選課(學號,課程號,成績) 系部(系號,系名稱,系主任):-主--)選擇合適的數據類型。定義必要的主鍵和索引。SQL4個表中盡可能的多輸入些數據(每個表不能少于10條記錄要求記錄不僅滿足數據約束要求,還要有表間關聯的記錄。二.實現方法創建數據庫和查看數據庫屬性。/*Author:182054421李張管Topic:在SQLServer中創建數據庫*/--創建數據庫CreatedatabaseStudenton(name='Product', --數據文件fileName='F:\數據庫原理及應用\實驗一\Product.mdf')logon(name='Product_log',--事務日志文件fileName='F:\數據庫原理及應用\實驗一\Product_log.ldf')Go--修改數據庫AlterdatabaseStudentmodifyname=lizhangguan@zhangsan;--查看數據庫屬性execsp_helpdbStudent創建表、確定表的主碼。--創建學生表(學號、姓名、年齡、性別、所在系)createtableStudent(Student_Snochar(4)primarykey, Student_Snamevarchar(20)uniquenotnull,Student_Sagevarchar(20),Student_Ssexvarchar(4),Sdept_Snochar(4),foreignkey(Sdept_Sno)referencesSdept(Sdept_Sno) onupdatecascade)InsertintoStudentvalues('0001','李一','18','男','0001'); --插入數據InsertintoStudentvalues('0002','李二','18','男','0002');InsertintoStudentvalues('0003','李三','18','男','0003');InsertintoStudentvalues('0004','李四','18','男','0004');InsertintoStudentvalues('0005','李五','18','男','0005');InsertintoStudentvalues('0006','李六','18','男','0006');InsertintoStudentvalues('0007','李七','18','男','0007');InsertintoStudentvalues('0008','李八','18','男','0008');InsertintoStudentvalues('0009','李九','18','男','0009');InsertintoStudentvalues('0010','李十','18','男','0010');InsertintoStudentvalues('0011','李零','18','男','0011');createuniqueindexStusnoonStudent(Student_Sno); --建立索--創建課程表(課程號、課程名、先行課、學分)createtableCourse(Course_Cnochar(4),Course_Cnamevarchar(20)uniquenotnull,Course_Cagevarchar(4),Course_Ccreditvarchar(4),Primarykey(Course_Cno), --在表級定義主碼foreignkey(Course_Cage)referencesCourse(Course_Cno)--通過外鍵實現表間聯系onupdatecascade)altertableCoursealtercolumnCourse_Cagechar(4);--修改表的結InsertintoCoursevalues('0001','科目一',NULL,'1'); --插入數據InsertintoCoursevalues('0002','科目二',NULL,'2');InsertintoCoursevalues('0003','科目三',NULL,'3');InsertintoCoursevalues('0004','科目四',NULL,'4');InsertintoCoursevalues('0005','科目五',NULL,'5');InsertintoCoursevalues('0006','科目六',NULL,'6');InsertintoCoursevalues('0007','科目七',NULL,'7');InsertintoCoursevalues('0008','科目八',NULL,'8');InsertintoCoursevalues('0009','科目九',NULL,'9');InsertintoCoursevalues('0010','科目十',NULL,'10');InsertintoCoursevalues('0011','科目十一',NULL,'11');createuniqueindexCoucnoonCourse(Course_Cno); --建立索引--創建選課表(學號、課程號、成績)createtableCourseSelection(Student_Snochar(4),Course_Cnochar(4),CourseSelection_Cgradevarchar(4),Primarykey(Student_Sno,Course_Cno), --在表級定義主碼foreignkey(Student_Sno)referencesStudent(Student_Sno) onupdatecascade,foreignkey(Course_Cno)referencesCourse(Course_Cno)--通過外鍵建立表間聯系onupdatecascade)InsertintoCourseSelectionvalues('0001','0001','100');InsertintoCourseSelectionvalues('0001','0002','100');InsertintoCourseSelectionvalues('0001','0003','100');InsertintoCourseSelectionvalues('0002','0001','100');InsertintoCourseSelectionvalues('0003','0001','100');InsertintoCourseSelectionvalues('0004','0001','100');InsertintoCourseSelectionvalues('0005','0001','100');InsertintoCourseSelectionvalues('0006','0001','100');InsertintoCourseSelectionvalues('0007','0001','100');InsertintoCourseSelectionvalues('0008','0001','100');InsertintoCourseSelectionvalues('0009','0001','100');--創建系部表(系號、系名稱、系主任)createtableSdept(Sdept_Snochar(4)primarykey,Sdept_Snamevarchar(20)uniquenotnull,Sdept_Sdirectorvarchar(20),)InsertintoSdeptvalues('0001','一系','張一'); --插入數據InsertintoSdeptvalues('0002','二系','張二');InsertintoSdeptvalues('0003','三系','張三');InsertintoSdeptvalues('0004','四系','張四');InsertintoSdeptvalues('0005','五系','張五');InsertintoSdeptvalues('0006','六系','張六');InsertintoSdeptvalues('0007','七系','張七');InsertintoSdeptvalues('0008','八系','張八');InsertintoSdeptvalues('0009','九系','張九');InsertintoSdeptvalues('0010','十系','張十');InsertintoSdeptvalues('0011','十一系','張零');createuniqueindexSdesnoonSdept(Sdept_Sno); --建立索引查看和修改表結構。--查看表select*FromStudent;select*FromCourse;select*FromCourseSelection;select*FromSdept;可視化方法:右鍵表名-編輯前200行--修改表的結構altertableStudentalt
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 危險品包裝可視化設計的互動性研究考核試卷
- 五金行業區域一體化與數字經濟發展融合考核試卷
- 處理設施生命周期成本分析考核試卷
- 綠色供應鏈與企業內部環境管理體系整合考核試卷
- 租賃設備租賃保險管理考核試卷
- 住宅風水與室內空氣質量控制考核試卷
- 人臉識別在無人零售場景下的商品質檢探討考核試卷
- 2025年中國PU水晶膠數據監測研究報告
- 2025年中國IC測試座數據監測研究報告
- 2025年中國DSNG數字電視激勵器數據監測研究報告
- 公安網絡安全培訓
- 唐山購房協議模板
- 旅拍運營方案
- 國開 電大《政治學原理》形考測試一答案
- 高中化學乙醇教學反思
- 如皋市直屬機關遴選筆試真題
- 2022-2023學年山東省濟南市高一下學期期末數學試題(解析版)
- 2022-2023學年安徽省阜陽市高一下學期期末教學質量統測數學試卷(解析版)
- 華東師大版數學七年級上冊教案全冊
- 醫患之間暴力行為預防與處理管理制度
- 2022年版初中物理課程標準解讀-課件
評論
0/150
提交評論