当前位置: 首页 > news >正文

编程语言:SQL Server数据库使用教程,SQL Server增删改查语句

「作者主页」:士别三日wyx
「作者简介」:CSDN top100、阿里云博客专家、华为云享专家、网络安全领域优质创作者
「推荐专栏」:对网络安全感兴趣的小伙伴可以关注专栏《网络安全自学教程》

SQL Server是微软提供的一种关系型数据库,语法跟MySQL类似,这篇文章主要是熟悉SQL Server的语句格式,会脱裤、在告警流量中能认出来即可。

SQL Server

  • 1、表操作
    • 1.1、创建表
    • 1.2、删除表
    • 1.3、修改表
  • 2、数据操作
    • 2.1、新增
    • 2.2、删除
    • 2.3、修改
    • 2.4、查询
      • 2.4.1、模糊查询
      • 2.4.2、范围查询
      • 2.4.3、子查询
      • 2.4.4、排序
      • 2.4.5、去重
      • 2.4.6、前n行

1、表操作

1.1、创建表

create table teacher(id int primary key,name varchar(10) not null,age int)

1.2、删除表

drop table teacher;

1.3、修改表

alter table teacher		-- 添加字段
add name varchar(10) not null;alter table teacher		-- 删除字段
drop column name;exec sp_rename 'teacher.name','newname','COLUMN';	-- 修改字段alter table teacher		-- 修改字段类型
alter column name varchar(10) not null;

2、数据操作

2.1、新增

insert into test.dbo.users (id,username,password)
values(1,'lisi',123),(2,'lisi',123);insert into test.dbo.users (id,username,password)	-- 将查询结果插入
select * from test.dbo.users;

2.2、删除

delete test.dbo.users where id=1

2.3、修改

update test.dbo.users set username='aaa' where id=1;

2.4、查询

select * from test.dbo.users    -- 普通条件查询
where id=1;

2.4.1、模糊查询

select * from test.dbo.users
where username like '%li%';

2.4.2、范围查询

select * from test.dbo.users	-- id在1~3之间的数据
where id between 1 and 3;select * from test.dbo.users	-- id在1~3以外的数据
where id not between 1 and 3;

2.4.3、子查询

select * from test.dbo.users	-- id为1或2或3的数据
where id in(1,2,3);select * from test.dbo.users	-- id不是1或2或3的数据
where id not in(1,2,3);

2.4.4、排序

select * from test.dbo.users	-- 从小到大排序
order by id asc;select * from test.dbo.users	-- 从大到小排序
order by id desc;

2.4.5、去重

select distinct * from test.dbo.users;	-- 去重

2.4.6、前n行

select top 3 * from test.dbo.users;		-- 前n行

http://www.lryc.cn/news/310109.html

相关文章:

  • 【tableau学习笔记】tableau无法连接数据源
  • cetos7 Docker 安装 gitlab
  • 无极低码:无极低码部署版操作指南
  • C语言实现日本某地发生了一件谋杀案
  • 【C++】const成员
  • 利用小蜜蜂AI智能问答ChatGPT+AI高清绘图生成图文故事案例
  • Github项目推荐-LightMirrors
  • day14:栈排序
  • 【LeetCode:2368. 受限条件下可到达节点的数目 + BFS】
  • pyorbbecsdk奥比中光python版本SDK在Windows下环境配置笔记
  • YOLOV8介绍
  • 【ElfBoard】基于 Linux 的智能家居小项目
  • 自动化测试介绍、selenium用法(自动化测试框架+爬虫可用)
  • 深度学习的一个完整过程通常包括以下几个步骤
  • WPS如何共享文件和文件夹
  • PowerData 2024“数字经济-城市开源行”活动预告
  • QT多语言切换功能
  • windows上elasticsearch的ik分词器的安装
  • 基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的口罩识别系统(Python+PySide6界面+训练代码)
  • 在Windows系统中启动Redis服务
  • k8s.gcr.io/pause:3.2镜像丢失解决
  • 全面整理!机器学习常用的回归预测模型
  • 在vue中对keep-alive的理解,它是如何实现的,具体缓存的是什么?
  • 章节一、认识three.js与开发环境学习笔记01;
  • QT摄像头采集
  • C语言第三十四弹---动态内存管理(下)
  • PDN分析及应用系列二-简单5V电源分配-Altium Designer仿真分析-AD
  • Vue开发实例(一)Vue环境搭建第一个项目
  • 将SpringBoot项目改造成solon项目
  • 更详细的软件测试理论基础:流程,开发、测试模型,测试分类,测试用例及其设计方法,缺陷