表(SQL SERVER)

表(SQL SERVER)
1.新建一个名为spgl的数据库,在该数据库中再建两个数据表,一个spb表(商品编号,商品名称,商品产家等信息)采用SQL Server Management Studio方式建立,另一个ygxxb表(员工编号,姓名,性别,电话)使用CREATE命令建立。
创建数据库
create database spgl
on
(name=spgl,
filename='D:\201018280120易小群\spgl.mdf')
go
创建表
use spgl
go
create table spb
(商品编号nvarchar(12) not null,--注意,商品编号与nvarchar(12)即数据类型之间要有空格分隔
商品名称nvarchar(20) not null,
商品产家nvarchar(20) not null)
go
use spgl
go
create table ygxxb
(员工编号nvarchar(12) not null,
姓名nvarchar(8) not null,
性别nvarchar(2) not null,
电话nvarchar(20) not null)
go
2、向spb增加两列名为“商品价格”和“生产日期”字段,并删除“商品产家”列信息。
use spgl
go
alter table spb
add 商品价格float not null,生产日期datetime not null--增加两列
go
use spgl
go
alter table spb
drop column 商品产家--删除商品产家列信息
go
3、用T_SQL语句删除ygxxb表
use spgl
go
drop table ygxxb--删除ygxxb表
go
4、向spb追加三条记录,记录内容为:2009031301,来一桶,3.5,20081201
2009031302,食用油,35,20081215
2009031303,东北米,1.5,20081010
use spgl
go
insert spb(商品编号,商品名称,商品价格,生产日期)
values('2009031301','来一桶','3.5','20081201')
go
use spgl
go
insert spb(商品编号,商品名称,商品价格,生产日期)
values('2009031302','食用油','35','20081215')
go
use spgl
go
insert spb(商品编号,商品名称,商品价格,生产日期)
values('2009031303','东北米','1.5','20081010')
go
5、修改编号为2009031302的商品名称为:剃须刀,并删除“东北米”记录。
use spgl
go
update spb
set
商品名称=剃须刀--修改的值
where
商品编号='2009031302'--条件表达式
Go
use spgl
go
delete spb
where 商品名称=东北米--删除符合条件的项
go
Tags: 

延伸阅读

最新评论

发表评论