------------------------------------
Windows Phone 7手机开发、
.Net培训、期待与您交流!------------------------------------
索引
全表扫描:对数据进行检索(select)效率最差的是全表扫描,就是一条条的找。
select *from tableName [where col=...]
创建索引能提高查询效率,但是索引是占空间的,而且添加,更新,删除数据的时候也需要同步更新索引,因此会降低insert,update,delete的速度。我
们一般只在经常检索的字段上(where语句后)创建索引。
创建索引的方式,在表设计器中点击右键,选择“索引/键”——》添加-》在列中专责索引包含的列。
即使创建了索引,任然有可能全表扫描,比如like,函数,类型转换等。
--------------------------------------------------------------------
表连接Join与子查询
join方面看参考书
有客户表(T_Customers)和订单表(T_Orders)两个表,客户表字段为:Id,Name,Age订单字符按为:Id,BilNo,CustomerID,订单表通过
Customerid关
联客户表。
select o.billNo,c.Name,c.age
from t_orders as o jion t_customers as c
on o.customerid=c.id
1,将一个查询语句做为一个结果集供其他sql语句使用,就像使用普通的表一样,被当做结果集的查询语句被称为子查询。所有可以使用表的地方几乎都
可以使用子查询来代替。
如:
select *from (select *from t1 where fage<30) as t2
2。单值做为子查询:select 1as f1,2 as f2,(select min(yearPublished) from t_book) as f3,(select max(yearPublished) from
t_book)) as f4
只有返回一行一列的数据的子查询才能当成单值子查询。下面是错误的
如:
select 1 as f1,2,(select yearPublished from t_book)
select *from t_readerfavorite where fcategoryid=(select fid from
t_category where fname='Story'
)
select *from t_readerfavorite where fcategoryid in (select fid from
t_category)
限制结果集
select *from
(
select row_number() over(ordery by fsalary desc) as rownum,
fnumber,fname,fsalary,fage from t_employee
) as e1
where e1.rownum>=3 and e1.rownum<=5
------------------------------------ Windows Phone 7手机开发、 .Net培训、期待与您交流!------------------------------------
索引
全表扫描:对数据进行检索(select)效率最差的是全表扫描,就是一条条的找。
select *from tableName [where col=...]
创建索引能提高查询效率,但是索引是占空间的,而且添加,更新,删除数据的时候也需要同步更新索引,因此会降低insert,update,delete的速度。我
们一般只在经常检索的字段上(where语句后)创建索引。
创建索引的方式,在表设计器中点击右键,选择“索引/键”——》添加-》在列中专责索引包含的列。
即使创建了索引,任然有可能全表扫描,比如like,函数,类型转换等。
--------------------------------------------------------------------
表连接Join与子查询
join方面看参考书
有客户表(T_Customers)和订单表(T_Orders)两个表,客户表字段为:Id,Name,Age订单字符按为:Id,BilNo,CustomerID,订单表通过
Customerid关
联客户表。
select o.billNo,c.Name,c.age
from t_orders as o jion t_customers as c
on o.customerid=c.id
1,将一个查询语句做为一个结果集供其他sql语句使用,就像使用普通的表一样,被当做结果集的查询语句被称为子查询。所有可以使用表的地方几乎都
可以使用子查询来代替。
如:
select *from (select *from t1 where fage<30) as t2
2。单值做为子查询:select 1as f1,2 as f2,(select min(yearPublished) from t_book) as f3,(select max(yearPublished) from
t_book)) as f4
只有返回一行一列的数据的子查询才能当成单值子查询。下面是错误的
如:
select 1 as f1,2,(select yearPublished from t_book)
select *from t_readerfavorite where fcategoryid=(select fid from
t_category where fname='Story'
)
select *from t_readerfavorite where fcategoryid in (select fid from
t_category)
限制结果集
select *from
(
select row_number() over(ordery by fsalary desc) as rownum,
fnumber,fname,fsalary,fage from t_employee
) as e1
where e1.rownum>=3 and e1.rownum<=5
------------------------------------ Windows Phone 7手机开发、 .Net培训、期待与您交流!------------------------------------