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

如下内容基于此图编写!
在这里插入图片描述
全部的逗号和括号都必须使用英式逗号和括号
➤建立表:web

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)

➤更新数据:ide

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

➤删除数据:
删除表中全部信息,没法恢复!svg

truncate table information

删除表中全部信息,可恢复!code

delete from information

查询命令
查询表information全部信息⇓orm

select * from information

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

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

查询表中全部运维工程师的姓名⇓对象

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

查询表中基本工资为 8000~10000的员工全部信息⇓blog

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