您的位置:首页 > 娱乐 > 八卦 > SQL Server数据库 创建表,和表的增删改查

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

2024/10/6 12:27:02 来源:https://blog.csdn.net/2302_77639120/article/details/141402999  浏览:    关键词: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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com