随笔分类 - SQLserver学习
SQL Sever 身份验证 sa用户设置
摘要:1.用windows身份验证登陆数据库找到sa用户 2.鼠标右键sa->属性->常规,设置密码。 3.选择状态->登陆选择已启用 4.选中当前数据库 鼠标右键->属性 5.选择安全性->SQL Server和Windows 身份验证。。。 如果sa用户登陆出现 错误:18456 可能第5步没有做。
阅读全文
SQL 过滤 having
摘要:select * from emp--having 对分组之后使用--输出部门号 和 部门的平均工资 并且 平均工资 > 2000select deptno, avg(sal) as "平均工资" from emp group by deptno having avg(sal)...
阅读全文
SQL 分组查询 group by
摘要:select * from emp--deptno 为部门号--输出每个部门的编号 和 该部门的平均工资--group by deptno; 通过deptno分组select deptno, avg(sal) as "部门平均工资" from emp group by deptno;
阅读全文
SQL 自动增长 identity
摘要:create table Users(id int identity(10000,1),--id 从10000开始,增加长度为1name nvarchar(10),);--执行三次这个语句insert into Users values('小昆虫');
阅读全文
SQL 基本的函数
摘要:select * from emp;select max(sal) from emp;--sal中最大值select min(sal) from emp;--sal中最小值select avg(sal) from emp;--sal的平均值select count(sal) from emp;--统...
阅读全文
SQL like 模糊查询
摘要:select * from emp;--查询ename中含有A的字母select * from emp where ename like '%A%';--查询ename中第一个字母是A的输出select * from emp where ename like 'A%';--查询ename中末尾字母为...
阅读全文
SQL order by 两个字段排序
摘要:select * from emp;--先按照sal排序,如果sal相同,就按照deptno排序select * from emp order by sal, deptno;--先按照deptno排序,如果deptno相同,就按照sal排序select * from emp order by dep...
阅读全文
SQL isnull函数
摘要:select * from emp;--就算年收入:sal*12+comm,sal为月工资,comm为年薪select ename, sal*12+isnull(comm, 0) from emp;--为什么要使用isnull函数,因为null值不能参加运算select ename, sal*12+...
阅读全文
SQL null值 查询null
摘要:select * from emp;--查询comm为null的员工信息select * from emp where comm is null;--查询comm不为null的员工信息select * from emp where comm is not null;
阅读全文
SQL top order between 一起使用
摘要:select * from emp;--输出工资在[1500,3000]范围之内的工资最高的前5个员工信息select top 5 * from emp where sal between 1500 and 3000 order by sal desc;
阅读全文
SQL order 排序
摘要:select * from emp;--按照工资升序排序select * from emp order by sal;--按照工资降序排序select * from emp order by sal desc;
阅读全文
SQL top查询
摘要:select *from emp;--查询表前5行 员工信息select top 5 * from emp;--查询表前15%行的员工信息select top 15 percent * from emp;
阅读全文
SQL in查询
摘要:--sal为员工工资select * from emp;--查询工资等于1500或3000或5000的用户信息select * from emp where sal in (1500, 3000, 5000);select * from emp where sal = 1500 or sal = 3...
阅读全文
SQL between查询 范围查询
摘要:--sal为员工工资select * from emp;--查询工资在[1500,3000]范围的员工信息select * from emp where sal >= 1500 and sal <= 3000;select * from emp where sal between 1500 and ...
阅读全文
SQL 2008 数据库只读 修改
摘要:先对数据库分离 数据库鼠标右键->任务->分离将UsersDB.mdf UsersDB_log.LDF文件 属性->安全->编辑两个文件的都要更改权限然后在附加数据库 数据库鼠标右键->附加 选择文件路径
阅读全文
SQL distinct
摘要:select *from emp;select deptno from emp;select distinct deptno from emp;--过滤deptno 重复的数据distinct 对null也会过滤select distinct comm, deptno from emp;--过滤co...
阅读全文
SQL 简单查询语句 select
摘要:select *from emp;//查询emp表内容select ename, job from emp;//从emp表中查询ename和job列select ename, sal from emp;//在表emp中查询ename和sal列select ename, sal*12 from emp...
阅读全文
SQL 启动服务方法
摘要:(1)windows开始菜单->Microsoft SQL Server 2012->配置工具->配置管理器查看服务(2)win7 将鼠标移到菜单栏->鼠标右键->任务管理器选择服务这是window自带服务在右边任意选中一个,在键盘上输入sq(3)计算机鼠标右键->管理
阅读全文