Use SQL Server to manage data tables

"Introduction to Database System" Experimental Report

date

2020/9/13

Topic: Use SQL Server to manage data tables

Name

 

student ID

 

lab environment:

A computer with SQL Server 2005/2008 installed

Experiment content and completion status:

Please use Management Stuio and T-SQL to complete the following:

  1. Please complete the following in the designated database:
  1. Create a corresponding data table based on the structure of the data table, the table structure is as follows;

Student Information Form (student)

Field Name

Field type and length

Description

Remarks

Sno

Char(9)

Student ID

Primary key

Take off

Char(6)

student name

non empty

Ssex

Char(2)

Student gender

Can be empty

Sage

Int

Student age

Can be empty

Sdept

VarChar(8)

Student's Department

Can be empty

 

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

 

Course Information Sheet (course)

Field Name

Field type and length

Description

Remarks

Cno

Char(4)

Course No

Primary key

Cname

VarChar(20)

Course Title

non empty

Cpno

Char(4)

Advance lesson

Can be empty

Credit

Int

credit

Can be empty

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

 

Course selection information form (sc)

Field Name

Field type and length

Description

Remarks

Sno

Char(9)

Student ID

Primary key

Cno

Char(4)

Course No

Primary key

Grade

Int

Grades

Can be empty

 

 

 

 

 

T-SQL

 

 

2) Add a new field "class name (sclass)" in the table student;

 

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

3) Delete the field "class name (sclass)" in the table student;

Click on the row of Sclass to delete the column

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

4) Modify the length of the field named "sname" in the student table from the original 6 to 8;

 

 

 

 

 

 

 

T-SQL

 

 

 

5) Modify the name of the field "sdept" in the student table to "dept" and the length to 20;

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

6) Modify the sage field name in the student table to sbirth and the type to smalldatetime;

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

7) Modify the new name of the table student to stu_info;

Right click on the table and select Rename

 

 

 

 

 

T-SQL

 

 

 

8) Delete the data table student;

Right click on the table and select delete

 

 

 

 

T-SQL

 

 

 

2. Create teacher teaching management database JSSK and complete the following content;

  1. Create the following three tables in the database JSSK;

Table name: teachers

Column name

type of data

Description

description

Tno

Character type, length 7

Primary key

Teacher ID

Tname

Character type, length 10

non empty

Name

Tsex

Character type, length 2

The default value is "male"

gender

Birthday

Small date and time type

Allow empty

date of birth

Dept

Character type, length 20

Allow empty

Department

Sid

Character type, length 18

 

identity number

 

 

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

 

 

Table name: lessons

Column name

type of data

Description

description

Cno

Character type, length 10

Primary key

Course ID

Cname

Character type, length 20

non empty

course name

Credit

Short integer

 

credit

property

Character type, length 10

 

Course nature

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

表名: shouke

列名

数据类型

说明

描述

Tno

字符型,长度7

主键

教师号

Cno

字符型,长度10

主键

课程名

Hours

整数

 

课时

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

2)在shouke表里添加一个授课类别字段,列名为Type,类型为Char,长度为4;

 

 

 

 

 

 

 

T-SQL

 

 

 

 

3)将shouke表的Hours的类型改为smallint;

 

 

 

 

 

 

 

T-SQL

 

 

4)删除lessons表中的property列;

点击property所在的行,删除列

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

 

3、(选做)创建产品销售数据库CPXS,数据文件的逻辑文件名为cpxs_data,物理文件名为D:\sql\cpxs.mdf;文件初始大小为2MB,自动增长,每次增长1MB;日志文件逻辑文件名为cpxs_log,物理文件为;文件初始大小2MB,自动增长,每次增长15%;

T-SQL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1)在数据库CPXS中创建下列三张表;

表名:产品表(cp)表结构

列名

数据类型

说明

描述

Cpbh

字符型,长度6

主键

产品编号

Cpmc

字符型,长度30

非空

产品名称

Jg

浮点型,长度8

允许空

价格

Kcl

整型,长度4

允许空

库存量

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

表名:销售商(xss)表结构

列名

数据类型

说明

描述

Xsbh

字符型,长度6

主键

销售商编号

Xsmc

字符型,长度30

非空

销售商名称

Dq

字符型,长度10

允许空

地区

Fzr

字符型,长度8

允许空

负责人

Dh

字符型,长度12

允许空

电话

Bz

文本,长度16

允许空

备注

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

 

 

表名: 产品销售(xss)表结构

列名

数据类型

说明

描述

Cpbh

字符型,长度6

主键

产品编号

Xsbh

字符型,长度6

主键

销售商编号

Xssj

Datetime,长度8

非空

销售时间

Sl

整型,长度4

非空

数量

Je

浮点型,长度8

非空

金额

 

 

 

 

 

 

 

 

 

T-SQL

 

 

 

 

 

 

出现的问题及解决方案:

使用T-SQL语句修改表名称,字段名称,字段类型时,不清楚具体方法,在网上查找方法,完成本次实验。

教师评语及得分:

           

 

 

Guess you like

Origin blog.csdn.net/weixin_48450741/article/details/112464376
Recommended