0
点赞
收藏
分享

微信扫一扫

【无标题】SQLserver基础语法

小禹说财 2022-02-11 阅读 95

--数据库

create database yyy

--用户表

create table tb_users(

  uid int primary key identity(1,1),--用户编号

  uname varchar(20) not null,--用户名

  upwd varchar(16) not null default('888888'),--密码

  usex varchar(2) not null check (usex='男' or usex='女'),--性别

  uage int not null check(uage>0 and uage<150),--年龄

  usf varchar(20) not null--身份

);

 

--用户表增加数据

insert into tb_users values('张三','12345','女',17,'普通用户');

insert into tb_users values('李四','67899','女',17,'普通用户');

insert into tb_users values('王二','12565','女',17,'普通用户');

insert into tb_users values('杨麻子','98766','男',22,'普通用户');

 

--用户表删除数据

delete from tb_users where uid=4;

 

--用户表修改数据

update tb_users set uname='小张' where uid=1;

update tb_users set uname='小李' where uid=2;

update tb_users set uname='小王' where uid=3;

 

--用户表查询所有数据

select * from tb_users;

--------------------------------------------------------------------------

--客户类型表

create table tb_type(

 tid int primary key identity(1,1),--类型编号

 tname varchar(20) not null,--类型名

 tmenu varchar(30)--备注

);

 

--客户类型表增加数据

insert into tb_type values('暴发户','好好招待');

insert into tb_type values('财阀','手里捧着');

insert into tb_type values('拆迁户','当成上帝');

insert into tb_type values('土豪','当成亲爹');

 

--客户类型表删除数据

delete from tb_type where tid=5;

 

--客户类型表修改数据

update tb_type set tname='大暴发户' where tid=1;

update tb_type set tname='大财阀' where tid=2;

update tb_type set tname='大拆迁户' where tid=3;

 

--客户类型表查询所有数据

select * from tb_type;

 

----------------------------------------------------------------------------

 

--客房表

create table tb_kefang(

 fid int primary key not null,--客房编号

 tid int not null foreign key references tb_type(tid),--类型编号

 fprice int not null,--房价

 fkzrs int not null,--可住人数

 fyzrs int not null default('0'),--已住人数

 fcnt int not null default('0'),--入住统计

 fmenu varchar(100) not null--备注

);

 

--客房表增加数据

insert into tb_kefang values(1,1,199,2,1,3,'好好招待');

insert into tb_kefang values(2,2,299,3,2,4,'手里捧着');

insert into tb_kefang values(3,3,399,4,3,5,'当成上帝');

 

--客房表删除数据

delete from tb_kefang where tid=3;

 

--客房表修改数据

update tb_kefang set fprice=299 where fid=1;

update tb_kefang set fprice=399 where fid=2;

update tb_kefang set fprice=499 where fid=3;

 

--客房表查询所有数据

select * from tb_kefang;

--------------------------------------------------------------------------

--登记表

create table tb_dengji(

  did int not null primary key,--编号

  dname varchar(20) not null,--客户名

  dfid int not null foreign key references tb_kefang(fid),--房间编号

  dsfz varchar(18) not null,--身份证号

  dyj float not null,--押金

  drz date not null,--入住时间

  dtf date --退房时间

);

 

--登记表增加数据

insert into tb_dengji values(1,'大张',1,12121212,200,'2020-01-02','2020-01-04');

insert into tb_dengji values(2,'大李',2,13131313,200,'2020-01-02','2020-01-04');

 

--登记表删除数据

delete from tb_dengji where did=2;

 

--登记表修改数据

update tb_dengji set dname='张杰' where did=1;

 

--登记表查询所有数据

select * from tb_dengji;

举报

相关推荐

【无标题】云计算网络基础

《无标题》

【无标题】[][]

【无标题】Java基础知识——异常

【无标题】无日

【无标题】填空

【无标题】1

【无标题】sss

0 条评论