--数据库所有表select * from sysobjects where type='u'; --指定表的所有列select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='T_EMPLOYEE')
帮助类 using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { public static class SqlServer { #region 样本 private static
实现功能: 1.先查询status=2的记录,如果查询到记录则返回第一条记录的Product_Name:2.如果查询不到status=2的记录,则判断status=1的记录是否存在,不存在则返回“请耐心等待!”,存在则返回“拆烟完毕!” 实现思路: 1.使用case语句返回不同的内容: case语句格式: case when 判断语句1 then 返回1 when 判断语句2 then 返回2 …… else 返回n end 2.解决无记录时需要返回一条null的数据: select Produ
1.查询语句的基本操作 - select - from - where - group by - having - distinct - order by - limit - 聚合函数: count, max, min, avg, sum 2.单表查询: #前期表与数据准备 # 创建一张部门表 create table emp( id int not null unique auto_increment, name ) not null, sex enum('male','female') no
编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据: 1.列出至少有一个员工的所有部门. SQL语句: select * from SCOTT.DEPT where deptno in (select distinct deptno from SCOTT.DEPT); 查询结果: 2.列出所有员工的姓名及其直接上级的姓名. SQL语句: select e.ename 员工姓名,m.ename 上级姓名 from scott.emp e,scott.emp m where
查看所有数据库名 select name from master..Sysdatabases order by name; 查看当前数据所有表 select name from sysobjects where xtype = 'U' ORDER BY name 查询所有表的数据结构(最牛逼的) then d.name else null end) 表名, a.colorder 字段序号,a.name 字段名, ( then '√'else '' end) 标识, (case when (SEL
--方法1[set statistic ]: set statistics time on go --执行语句 xxxx go set statistics time off --方法2[getDate()]: DECLARE @begin dateTime DECLARE @end dateTime SET @begin=getdate(); BEGIN --执行语句 xxxx end set @end=getdate(); SELECT datediff(ms,@begin,@end) as
查询指定字段 select 字段1,字段2 from 表名; 消除重复行(重复指的是结果集中的所有完全重复行) select distinct 字段1,字段2... from 表名 比较运算符(< > != = ) select * from 表名 where id>4 逻辑运算符(and or not in) select * from 表名 where id>4(条件1) and gender=1
select 身份证号 from (select 身份证号 from 表1 where 考试名称= 'aaa'union allselect 身份证号 from 表2 where 考试名称= 'bbb')as A group by 身份证号 HAVINGCOUNT (身份证号)>1 注:1.union 表示去掉重复的数据显示 2.union all表示显示所有数据,重复的多条显示 3.从结果中查询不加上 as A时会报错:关键字 'group' 附近有语法错误.