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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值