ASP.NET网站开发

本文探讨了ASP.NET网站开发中涉及的数据库操作,包括基础的数据库查询和删除记录,如示例所示:使用master数据库,删除Product表中ID为3的记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据库

use master

go

if exists(select * from sysdatabases where name = 'db_user')
    drop database db_user
go

create database db_user
go

use db_user
go

---用户表
if exists(select * from sysobjects where name = 'UserInfo')
    drop table UserInfo
go

create table UserInfo
(
    ID int identity(1,1) not null primary key, --id
    Username varchar(20) not null,             --姓名
    Password varchar(20) not null,             --密码
    Email varchar(50) not null                 --邮箱
)
go

--角色表
if exists(select * from sysobjects where name = 'Role')
    drop table [Role]
go

create table [Role]
(
    ID int identity(1,1) not null primary key,     --id
    RoleName varchar(10) not null                  --角色名
)
go


--用户角色信息表
if exists(select * from sysobjects where name = 'UserRole')
    drop table UserRole
go

create table UserRole
(
    id INT PRIMARY KEY IDENTITY(1,1),             --id
    UserID int references UserInfo(ID),           --用户id
    RoleID int references [Role](ID)              --角色id
)
go


--用户详细表
if exists(select * from sysobjects where name = 'Product')
    drop table Product
go

create table Product
(
    ID int identity(1,1) not null primary key,        --id
    Name varchar(200) not null,                       --作品名
    Remark varchar(50) not null,                      --说明
    UserId int references UserInfo(ID),               --用户id
    Price int default(0) not null,                    --价格
    CreateDate datetime default(getdate()) not null,  --创建时间
    LasterDate datetime default(getdate()) not null,  --结束时间
    [Status] int not null check([Status]=0 or [Status]=1 or [Status]=2)   --状态
)
go

--购物订单表
if exists(select * from sysobjects where name = 'Order')
    drop table [Order]
go
create table [Order]
(
    ID int identity(1,1) not null primary key,             --id
    OrderNo varchar(30) not null,                          --订单号
    UserId int references UserInfo(ID),                    --用户id
    CreateDate datetime default(getdate()) not null,       --创建日期
    [Status] int not null check([Status]=0 or [Status]=1)  --状态
)


insert into UserInfo
select 'admin','admin','admin@xiecan.cc'
union
select '张三','123456','zhangsan@xiecan.cc'
union
select '李四','111111','lisi@xiecan.cc'
union
select '王五','666666','wangwu@xiecan.cc'
union
select '赵六','888888','zhaoliu@xiecan.cc'
union
select '燕七','456789','yanqi@xiecan.cc'
union
select '娄艺潇','222222','louyixiao@xiecan.cc'
go

insert into [Role]
select '超级管理员'
union
select '管理员'
union
select '协管'
union
select '版主'
union
select '普通游客'
go


insert into UserRole
select 1,2
union
select 2,4
union
select 3,1
union
select 4,4
union
select 5,5
union
select 6,3
union
select 7,4
go

--向Product添加数据
insert into Product values('Java编程技术基础','Java入门级教科书',6,100,default,default,1)
insert into Product values('C#编程技术基础','C#入门级教科书',2,50,default,default,1)
insert into Product values('RFID射频识别技术','物联网专业教材',3,2,default,default,1)
go

--向[Order] 添加数据
insert into [Order] values('201404080786AC639',6,default,0)
insert into [Order] values('201404080786AC640',6,default,0)
insert into [Order] values('2014008010786AC888',4,default,0)
go


select * from UserInfo
select * from UserRole
select * from [Role]

select * from Product
select * from [Order]

select M.*,B.RoleName from UserInfo M inner join UserRole A on M.ID = A.UserID
inner join [Role] B on A.RoleID = B.ID
order by B.RoleName

--update UserInfo set Username='张小三' where ID=6

--delete Product where ID=3



ASP.NET网站开发















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值