SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student
查询操作是SQL语言中很重要的操作,我们今天就来详细的学习一下. 一.数据查询的语句格式 SELECT [ALL|DISTINCT] <目标列表达式>[,<目标列表达式> ....] --可以选择多个列 FROM <表名或视图名>[, <表名或视图名> ....]--可以选择多个表或视图 [ WHERE <条件表达式> ] --查询什么条件的数据 [ GROUP BY <列名1> [ HAVING <条件表达式> ] ]
SQL Server查询时添加一列连续的自增列 在SQL Server数据库中表信息会用到Identity关键字来设置自增列.但是当有数据被删除的话,自增列就不连续了.如果想查询出这个表的信息,并添加一列连续自增的ID,可用如下查询语句: select Row_Number() over ( order by getdate() ) as init , * from 表名