SQL server 开发技巧1

本文介绍了SQL Server中的一些实用技巧,包括获取最新插入记录的ID、清理计划缓存、视图上创建索引的方法以及聚集索引与非聚集索引的区别。这些技巧对于提升SQL Server的性能管理和日常维护十分关键。
1. How to get the id of current inserted record?
using @@identity keyword. 
E.G.
create table table1 (id int identity(1,1) not null, name nvarchar(64))
go
insert into table1('Hello world')
go
select @@identity

2. How to cleanup SQL server plan cache?
DBCC DROPCLEANBUFFERS -- cleanup all cache data
DBCC FREEPROCCACHE -- cleanup  plan cache

 

3. Can I create an index on the view?

Yes, the notice is the unique clustered index  must be created first. And you should use With SchemaBinding flag when creating.

E.G,

Create View v1 With SchemaBinding As SQL statement

GO

Create Index Unique Clustered idx_1 On [columns...] 

 

4. What's the different between Clustered Index and Index?

The difference is Clustered Index try to store the relation data in the same page on disk as possible.  But Index not. So, almost performance of  clustered index is better than Index, but when you re-create the Index or order by result set, it is low performance.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值