常用查询--SQLSever

use test1;
select * from sys.tables;

use test1
sp_columns S1;

-- 修改表S1的字段name长度为10
alter table S1
alter column [name] nvarchar(10);

-- 修改表S1的字段age为int型
alter table S1
alter column age int;

-- 修改表S1的字段age不为空(null)
alter table S1
alter column age int not null;

-- 向数据表S1中添加字段score1, score2, score3, grade
alter table S1
add score1 numeric(3, 1), score2 numeric(3, 1), score3 numeric(3, 1), grade int  not null default 1 

-- 设置数据表S的id为主键
alter table S1
add constraint S1_Pri primary key (id);

-- 更改数据表S1的字段名age为sAge
alter table S1
EXEC sp_rename 'S1.age', 'sAge', 'column';

-- 向数据表S1中添加记录
use test1
insert into S1 values('chen', 19, '001', '男', '99.5', 1, '88', '80');
insert into S1 values('java', 26, '002', '男', '97.5', 1, '78', '91');
insert into S1 values('python', 30, '003', '女', '96.5', 1,'61', '70');
insert into S1 values('c', 44, '004', '女', '60', 1, '59', '92');
insert into S1 values('c++', 44, '005', '女', '70',default, '82', '82');
insert into S1 values('db', 19, '006', '女', '99.5', 1, '91', '87');
insert into S1 values('php', 19, '007', '女', null, 1, '92', '84');


-- 查看数据表S1中的所有记录
use test1
select * from S1;

-- 查看数据表S中有多少个年级
use test1
select distinct grade from S1;

-- 查看数据表S中的全体学生的姓名,年龄,学号
-- method 1
use test1
select [name]  as '姓名', sAge '年龄', id '学号' from S1;


-- method 2
use test1
select [name]  as 姓名, sAge 年龄, id 学号 from S1;

-- 查询数据表S中字段id为001的学生的分数和年级
use test1
select [name] '姓名', score1 '分数', grade '年级' from S1 where id = '001';

-- 查询数据表S中字段分数大于等于80的学生
use test1
select * from S1
where score1 >= 80;

-- 查询数据表S中分数大于等于80并且性别是男的学生
select * from S1 
where score1 >= 80 and sex = '男';

-- 查询数据表S中分数大于等于80并且性别是男,年级为1的学生
use test1
select * from S1
where score1 >= 80 and sex = '男' and grade = 1;

-- 查询数据表S分数不在80--90的学生
-- method 1
use test1
select * from S1
where score1 not between 80 and 100;

-- 查询数据表S中字段学号为001或002或005并且分数大于80的学生
-- method 1
use test1
select * from S1
where id in ('001','002', '005') and score1 >= 80;

-- method 2
use test1
select * from S1
where (id = '001' or id = '002' or id = '005') and score >= 80;

-- 查询数据表S字段学号既不是001也不是002的学生
use test1
select * from S1
where id <> '001' and id <> '002';

-- 查询数据表S中字段名字带有c的学生
use test1
select * from S1
where [name] like '%c%';

-- 查询数据表S中姓c的学生
use test1
select * from S1
where [name] like 'c%';

-- 查询数据表S中字段名字第二个是h的学生
use test1
select * from S1
where [name] like '_h%';

-- 查询数据表S中字段分数为空的学生
use test1
select * from S1
where score1 is null;

-- 查询第三个学生的记录
SELECT TOP 1 * FROM dbo.TB_Student WHERE StuID NOT IN (SELECT TOP 2 StuID FROM dbo.TB_Student);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在使用Spring Boot与MyBatis-Plus连接SQL Server时,可能会遇到以下问题: 1. 驱动问题:首先需要引入SQL Server的JDBC驱动,可以在pom.xml文件中添加依赖。常用的驱动有`com.microsoft.sqlserver.jdbc.SQLServerDriver`和`net.sourceforge.jtds.jdbc.Driver`。确保驱动版本与SQL Server版本兼容。 2. 数据库连接配置:在application.properties或application.yml文件中,需配置SQL Server的连接信息,包括数据库地址、端口、用户名、密码等。注意要正确配置驱动名称、连接URL以及字符集等。 3. 数据库版本兼容性:确保使用的SQL Server版本与MyBatis-Plus和JDBC驱动兼容。不同版本的SQL Server可能在SQL语法、特性或驱动接口上有所区别。 4. 数据库表映射:在使用MyBatis-Plus进行ORM映射时,需要在实体类中使用注解配置数据表名、字段名和主键等信息。同时,要确认实体类和数据表的字段类型、长度、精度等匹配。 5. 数据库连接池配置:可以使用Spring Boot提供的连接池技术,如HikariCP或Tomcat连接池。根据并发需求和性能要求,配置合适的连接池大小、最大等待时间和最大空闲时间等参数。 6. 异常处理与日志记录:在连接SQL Server过程中,可能会出现连接异常、语法错误等问题。需要适当处理这些异常,并进行日志记录以便排查和分析问题。 通过解决上述问题,我们可以成功连接SQL Server数据库,并使用MyBatis-Plus进行数据操作和ORM映射。持续的测试和调试可以保证系统的稳定性和性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MC6058

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值