2实验二 通过SQL语句创建与管理数据表
更新时间:2023-12-10 10:12:01 阅读量: 教育文库 文档下载
- 2实验二常用网络命令操作推荐度:
- 相关推荐
实验二 通过SQL语句创建与管理数据表
一、实验目的
(1)掌握查询分析器的使用。
(2)掌握通过SQL语句创建表的方法。 (3)掌握通过SQL语句修改表结构的方法。
(4)掌握通过SQL语句添加、修改、删除表数据的方法。
二、实验内容
1、通过SQL语句删除表
用SQL语句在数据库Student_info中删除实验一创建的Student表、Course表、SC表。 1、选择Student_info数据库,在该数据库环境中“新建查询”,然后完成删除操作
2、分别填写如下SQL语言 ①、drop table Student
②、drop table Course
③、drop table SC
3、删除操作完成
2、通过SQL语句创建表
用SQL语句在数据库Student_info中创建实验一中的Student表、Course表、SC表,结构如实验一中表2、表3、表4(即创建出空表即可)所示 ①、创建Student表
create table Student( Sno char(8) primary key, Sname varchar(8) not null, Sex char(2) not null,
Birth smalldatetime not null, Classno char(3) not null,
Entrance_date smalldatetime not null, Home_addr varchar(40) )
②、创建Course表
create table Course( Cno char(3) primary key, Cname varchar(20) not null,
Total_perior smallint check(Total_perior>0), Credit tinyint check(Credit<=6 and credit>0) )
③、创建SC表
create table SC( Sno char(8) not null, Cno char(3) not null,
Grade tinyint check(Grade>=0 and Grade<=100), primary key(Sno,Cno),
foreign key(Sno) references Student(Sno), foreign key(Cno) references Course(Cno) )
3、通过SQL语句管理表结构 (1)添加和删除列
a. 给Student表增加身高(以米单位)Stature列 ,类型为numeric(4,2),允许为空
值,且身高值需小于3.0米。
alter table Student add Stature numeric(4,2)
check(Stature<=3.0 and Stature>=0)
b. 给Student表增加所在系Sdept列,字符型,长度2,不允许为空值。
alter table Student add Sdept char(2) not null
c. 给Student表增加邮政篇码Postcode列,字符型,长度为6,可以为空,若不为空时,则要求其值只能出现数字,不能是其它字符。
alter table Student add Postcode char(6)
check(Postcode Like '[1-9][0-9][0-9][0-9][0-9][0-9]')
d.删除Student表中身高Stature列。
①、添加Stature列时就已知该列存在约束条件,若要删除该列,必须先删除约束条件,则
首先必须先找出约束条件的约束名称。以下有两种方法:
1、写入SQL语句找出
alter table Student drop column Stature
2、运用企业管理器找出 a、打开Student表
b、选择Stature行,单击右键,选择“CHECK约束”
c、约束名称显而易见
②、其次删除Stature约束
正在阅读:
2实验二 通过SQL语句创建与管理数据表12-10
《妇产科护理学》练习题(专科) - 309-17
2016-2017学年一2.2.1(2)对数与对数运算学案03-17
地板的分类和保养知识06-07
继续教育6分题03-30
浙江省生产建设项目水土保持管理办法11-01
二年级语文试卷及答案01-19
CAD制图线型规定学习资料04-05
石油经济学03-26
直流式对焊截止阀 - 图文05-11
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 数据表
- 语句
- 创建
- 通过
- 实验
- 管理
- SQL
- 甲醇生产工艺过程的安全措施与分析
- 传感器复习题与答案
- 100所名校2019届山东省日照一中高三上学期第二次质量达标检测数学(理)试题(解析版)
- 佛山市顺德区2019版一年级数学(下册)期中考试试卷 外研版B卷
- 数控技术考试试卷(附答案)
- 采用CSP工艺开发集装箱用高耐候钢的生产实践 - 图文
- 超星尔雅尔雅通识大学生心理健康教育答案
- 2017年上半年陕西省基金从业资格:期货市场的基本功能模拟试题
- 管理学案例分析
- 大型厂区网络视频监控解决方案 - 图文
- 形体训练与舞蹈编导基础第十节 云南花灯反崴-教案
- 第三章 药物代谢动力学
- 小学四年级下册奥数讲义确定稿
- 十三种蒙太奇镜头举例分析 - 图文
- 七年级地理下册7.2《“鱼米之乡”长江三角洲地区》习题2鲁教版五四制
- 河北省2017年资产评估师《资产评估》:中国资产评估准则体系的发展考试题
- 美学专题复习指导及复习题
- 法理学试卷
- 汽油机油项目可行性研究报告(目录) - 图文
- 个税专家杨巍解读避税误区,42个精选问答实录(老会计人的经验)