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

SQL Server数据库 创建表,和表的增删改查

打开SQL Server工具,连接服务器

右击数据库,创建新的数据库

新建表

填写列,我添加了Id,Name,Sex,Age,和class列

右键表刷新一下就有了

我又同时创建了一个Class表

 点击新建查询,现在写代码添加数据,也可以操作表来对数据进行添加

右键表,点击编辑,就可以直接添加数据

 代码添加数据

 先查看一下表,我习惯看着表编辑

select * from Students
select * from Class

添加单条数据 

insert into 表名 values(列对应的值)

insert into Students values (1,'张三','男',18,3)

添加多条数据

语法:

insert into 表名

select 列对应的值 union

select 列对应的值 union

select 列对应的值

insert into Students 
select 2,'李四','男',17,null union
select 3,'王五','男',19,1 union
select 4,'赵六','女',17,1 union
select 5,'小七','男',18,2 union
select 6,'老八','女',20,3 

修改

格式:update 表名 set 列名=新值,列名=新值 where 条件

修改李四的年龄为20

update Students set Age=20 where StudentID=2 

 删除

语法:delete from 表名 where 条件,一定要加where 添加,不然会删除很多,除非有备份,否则会很麻烦

delete from Students where StudentID = 6 
delete  Students where StudentID = 6 

删除老八

查看

语法:select * from 表名

查看全部

select * from Students

 

查看只名字和年龄

查询一列

语法:select 列名 from 表名

查询多列

语法:select 列名,列名 from 表名

select StudentName,Age from Students

区间查找

select * from Students where Age between 17 and 19        --  一般查询年龄区间
select * from Students where Age >=17 and  Age<= 19


http://www.mrgr.cn/news/10277.html

相关文章:

  • 高性能 Web 服务器:让网页瞬间绽放的魔法引擎(下)
  • 数学建模学习
  • 【Node】【3】回调函数
  • 如何本地搭建 Whisper 语音识别模型?一文解决
  • 【Python】机器学习中的 K-均值聚类算法及其优缺点
  • c++栈和队列(stack和queue)
  • 【图文并茂】ant design pro 如何对接登录接口
  • Python 和 PyCharm 安装(傻瓜式)
  • C++基础语法:异常处理(二)
  • TS学习笔记
  • Cocos Creator2D游戏开发(15)---预制体和按钮的绑定以及冷却效果的实现
  • Docker数据卷使用手册
  • 【Excel】Excel小技巧(实时更新中)- 0.0.1
  • Linux文件编程(系统API调用)
  • 幅频特性曲线分析及使用WPF绘制
  • 2024手把收教你下载FL Studio 24.1.1.4239中文版破解版图文激活教程
  • Tcp VS Udp文件传输协议分析与比较
  • 深度学习----------------------残差网络ResNet
  • Unity-可分组折叠的Editor
  • wxpython Scintilla styledtextctrl滚动条拖到头文本内容还有很多的问题