T-SQL语句(创建、插入、更新、删除、查询...)

以下内容基于此图编写!
在这里插入图片描述
所有的逗号和括号都必须使用英式逗号和括号
➤创建表:

create table information
(
编号 int identity(1,1) not null,
姓名 nvarchar(50) not null,
身份证号 varchar(18) primary key,
职务 nvarchar(50) not null,
出生日期 datetime not null,
基本工资 money not null check(基本工资 >=0 and 基本工资 <=100000),
)

➤插入数据:

insert into wahaha (姓名,身份证号,职务,出生   日期,工资)
values
('赵四','111222333444555666','运维工程师','1995/1/1',8000)

➤更新数据:

update wahaha set 工资='1000'   //修改内容。
where 姓名='赵四'     //更新对象。

➤删除数据:
删除表中所有信息,无法恢复!

 truncate table information

删除表中所有信息,可恢复!

delete from information

查询命令
查询表information所有信息⇓

select * from information

查询information里姓名,职务,基本工资的内容⇓

select 姓名,职务,基本工资 from information

查询表中所有运维工程师的姓名⇓

select 姓名 from information where职务='运维工程师'    

查询表中基本工资为 8000~10000的员工所有信息⇓

select * from information where 基本工资 between 8000 and 10000 

查询表中基本工资低于10000或高于20000的员工所有信息⇓

select * from information where 基本工资<10000 or 基本工资>20000  

查询表中基本工资为8000,9000,10000的员工所有信息⇓

select * from information where 基本工资 in (8000,9000,10000)

查询身份证号以66开头的员工所有信息⇓

select * from information where 身份证号 like '66%'   

查询表中姓杨的运维工程师的信息⇓

select * from information where 姓名 like '杨%' and 职务='运维工程师' 

查询表中前五行的数据⇓

select * top 5 * from information 

查询表中所有信息按照基本工资从高到低显示查询结果⇓
注:asc表示升序,desc表示降序。

select * from information order by 基本工资 desc  

查询表中有哪些职务⇓

select distinct 职务 from information  

使用select生成新数据:
在表中查询到的所有员工姓名,身份证号,职务的信息后生成一个新表new1

select 姓名,身份证号,职务 into new01 from information
  • 6
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秋枫 ~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值