Redian新闻
>
best practices for sql developer
avatar
best practices for sql developer# Database - 数据库
e*n
1
【 以下文字转载自 Postdoc 讨论区 】
发信人: endaimien (endaimien), 信区: Postdoc
标 题: 交了I-140绿卡申请表,还能延期DS-2019吗?
发信站: BBS 未名空间站 (Tue Jan 7 16:22:32 2014, 美东)
据我所知,交了I-140以后,J1签证申请肯定被拒。
但是我只延期DS2109,然后不申请J1,这样DS2109表的延期能成功吗?
avatar
g*l
2
随便总结了一下,不包括ETL,抛砖引玉了,
1. never use * in query, only use specific columns and rows you need, never
use extra
2. table uses dbo prefix, selection uses with (nolock)
3. repeated code section can be replace by UDF or stored procedure
4. join is always on the key. if join is not the key, you need to be very
careful
5. layout flow chart for complicated stored procedure before coding
6. CTE is a good choice to replace subquery, table variable and temp table
7. all the work should be done on the temp table to prevent blocking before
insert/update transaction table
8. use query execution plan for better performance
9. avoid cursor if possible.
10. avoid long update/insert/delete, use batch instead.
11. if value has no change, do not update. Comparison is less costly than
update in OLTP. use if exists to guard
avatar
e*n
3
【 以下文字转载自 Postdoc 讨论区 】
发信人: endaimien (endaimien), 信区: Postdoc
标 题: 交了I-140绿卡申请表,还能延期DS-2019吗?
发信站: BBS 未名空间站 (Tue Jan 7 16:22:32 2014, 美东)
据我所知,交了I-140以后,J1签证申请肯定被拒。
但是我只延期DS2109,然后不申请J1,这样DS2109表的延期能成功吗?
avatar
B*g
4
序号不对吧。
另外还是应该解释一下cursor。尽量不用cursor是指尽量不要用cursor一次只loop一个
record。

never
before

【在 g***l 的大作中提到】
: 随便总结了一下,不包括ETL,抛砖引玉了,
: 1. never use * in query, only use specific columns and rows you need, never
: use extra
: 2. table uses dbo prefix, selection uses with (nolock)
: 3. repeated code section can be replace by UDF or stored procedure
: 4. join is always on the key. if join is not the key, you need to be very
: careful
: 5. layout flow chart for complicated stored procedure before coding
: 6. CTE is a good choice to replace subquery, table variable and temp table
: 7. all the work should be done on the temp table to prevent blocking before

avatar
p*r
5
我理解是 不能。
avatar
g*l
6
有时候确实要用CURSOR的,虽然慢,但不LOCK,对特别忙的OLTP

【在 B*****g 的大作中提到】
: 序号不对吧。
: 另外还是应该解释一下cursor。尽量不用cursor是指尽量不要用cursor一次只loop一个
: record。
:
: never
: before

avatar
g*l
7
今天有个工作,大公司,PRINCIPAL SQL DEVELOPER,虽然不是喜欢的工作,我也去递
简历了,觉得自己比一般的DEVELOPER强。
avatar
s*0
8
能不能讲讲10的理由? 如果整个insert, update, delete 是在一个transcation里(
一有错就要全部rollback) 这么做不是更费事? 用不用batch所有的数据不是都一直被
lock着?
还有,你去面试SQL developer的时候是不是经常会被问到一些一般的programming的问
题? (像 class inheritance,algorithm 之类的问题?) 刚开始找新工作,已经连
着两次遇到这样的phone interview了,job description 里都是一些ETL,Data
Warehouse, reporting 和 building Cubes的要求,面试偏偏问了很多关于编程的东
西。
avatar
B*g
9
when you use batch, you can add COMMIT for each batch.

【在 s**********0 的大作中提到】
: 能不能讲讲10的理由? 如果整个insert, update, delete 是在一个transcation里(
: 一有错就要全部rollback) 这么做不是更费事? 用不用batch所有的数据不是都一直被
: lock着?
: 还有,你去面试SQL developer的时候是不是经常会被问到一些一般的programming的问
: 题? (像 class inheritance,algorithm 之类的问题?) 刚开始找新工作,已经连
: 着两次遇到这样的phone interview了,job description 里都是一些ETL,Data
: Warehouse, reporting 和 building Cubes的要求,面试偏偏问了很多关于编程的东
: 西。

avatar
g*l
10
TRANSACTION很忙的TABLE,你如果UPDATE的话,就会LOCK住TABLE,别人想INSERT
UPDATE DELETE就不行了,UPDATE的时间越长LOCK的时间也就越长,UPDATE语句
IMPLICITLY BEGIN TRAN COMMIT TRAN。所以分成几个小块去UPDATE,RUN完一个休息
一下,让其他的TRASACTION有时间COMPLETE,再RUN
下一个。比如,你要UPDATE一万个ORDR,估计一 下需要多长时间,如果UPDATE的VALUE
多,可能会10分钟,或者一个小时,可以分成10个TRANSACTION去 UPDATE,每个一分钟
或者6分钟,就不至于一LOCK就是一个小时,LOCK越来越多,系统就会出问题。
avatar
s*0
11
但是 ETL 的时候一个partially updated table是非常非常麻烦的。 你要多花很多功
夫设计 SSIS 里的restarting points。 (如果你commit一个 Foreach container
loop 里的每一个statement, 一旦运行到一半出了错你要restart会非常麻烦的。 特
别是有些type 2 slowly changing dimensions)
avatar
g*l
12
ETL是TOTALY DIFFERENT STORY了,我讲的是OLTP的系统,你的是OLAP的,OLAP讲的是利
用内存快速的把数据全部LOAD进LOCAL TABLE,避免VALIDATATION和DATA TYPE CHECK,
进到系统里以后再VALIDATE,这是我个人的经验。

【在 s**********0 的大作中提到】
: 但是 ETL 的时候一个partially updated table是非常非常麻烦的。 你要多花很多功
: 夫设计 SSIS 里的restarting points。 (如果你commit一个 Foreach container
: loop 里的每一个statement, 一旦运行到一半出了错你要restart会非常麻烦的。 特
: 别是有些type 2 slowly changing dimensions)

avatar
v*r
13
标题应该改一下: Best practices for sql developer of MS SQLServer.
不然很让人误解.
有些不敢苟同:
1. never use * in query ...
Comment: Never say "never", 难道就没有碰到过需要 query 一个表所有columns 的
时候?我是经常见:-)
4. join is always on the key ...
Comment: The joined columns don't have to be the key columns, for efficient
join, they just need to be indexed.
7. All the work should be done on the temp table to prevent blocking before
insert/update transaction table.
Comment: Poor design of Sybase (SQL Server should not be blamed:-) has made
this performance workaround a "best practice".
8. Avoid cursor if possible.
Comment: Again, poor implementation of Cursor concept(Sybase, SQLServer, not
sure which one should be blamed) has made Cursor, one of the most powerful
programming construct in Oracle, basically useless in SQLServer.

never
before

【在 g***l 的大作中提到】
: 随便总结了一下,不包括ETL,抛砖引玉了,
: 1. never use * in query, only use specific columns and rows you need, never
: use extra
: 2. table uses dbo prefix, selection uses with (nolock)
: 3. repeated code section can be replace by UDF or stored procedure
: 4. join is always on the key. if join is not the key, you need to be very
: careful
: 5. layout flow chart for complicated stored procedure before coding
: 6. CTE is a good choice to replace subquery, table variable and temp table
: 7. all the work should be done on the temp table to prevent blocking before

avatar
i*a
14
1. never use * in query ...
Comment: Never say "never", 难道就没有碰到过需要 query 一个表所有columns 的
时候?我是经常见:-)
Even if all columns are needed, avoid using select *. list all columns
specifically. So when somebody adds a column to the table it doesn't break
your program.

efficient
before

【在 v*****r 的大作中提到】
: 标题应该改一下: Best practices for sql developer of MS SQLServer.
: 不然很让人误解.
: 有些不敢苟同:
: 1. never use * in query ...
: Comment: Never say "never", 难道就没有碰到过需要 query 一个表所有columns 的
: 时候?我是经常见:-)
: 4. join is always on the key ...
: Comment: The joined columns don't have to be the key columns, for efficient
: join, they just need to be indexed.
: 7. All the work should be done on the temp table to prevent blocking before

avatar
g*l
15
任何事情都是有EXCEPTION,所谓BEST PRACTICE么,就是尽量地做到,做不到的时候要
小心。另外,还有人用SYBASE吗,死菜了?LOL
avatar
v*r
16
Agree, I used a bad excuses to justify use of "*". Still I will try to avoid
using "never" for proposing best practices.

【在 i****a 的大作中提到】
: 1. never use * in query ...
: Comment: Never say "never", 难道就没有碰到过需要 query 一个表所有columns 的
: 时候?我是经常见:-)
: Even if all columns are needed, avoid using select *. list all columns
: specifically. So when somebody adds a column to the table it doesn't break
: your program.
:
: efficient
: before

avatar
v*r
17
SQLServer 不是 Window 版的 Sybase 吗?

【在 g***l 的大作中提到】
: 任何事情都是有EXCEPTION,所谓BEST PRACTICE么,就是尽量地做到,做不到的时候要
: 小心。另外,还有人用SYBASE吗,死菜了?LOL

avatar
g*l
18
我都很久没有见过SYBASE SQL招人的广告了。

【在 v*****r 的大作中提到】
: SQLServer 不是 Window 版的 Sybase 吗?
avatar
B*g
19
要厚到,哈哈。

【在 g***l 的大作中提到】
: 我都很久没有见过SYBASE SQL招人的广告了。
avatar
v*r
20
大公司用 sybase 的还是不少吧.
想起了sybase 和 sqlserver 的老祖宗 Ingres. 头几年去一家公司,finance
application 还是 Ingres based, 我帮着管过几天. 去参加了一个 Ingres 的 User
group meeting, 到会的竟然有五十来家用户, 其中不乏一些大公司。 不过开完会回
来没多久我们就把它 migrate 到 Oracle 上去了。

【在 g***l 的大作中提到】
: 我都很久没有见过SYBASE SQL招人的广告了。
avatar
B*g
21
oracle有工作要贴出来。

【在 v*****r 的大作中提到】
: 大公司用 sybase 的还是不少吧.
: 想起了sybase 和 sqlserver 的老祖宗 Ingres. 头几年去一家公司,finance
: application 还是 Ingres based, 我帮着管过几天. 去参加了一个 Ingres 的 User
: group meeting, 到会的竟然有五十来家用户, 其中不乏一些大公司。 不过开完会回
: 来没多久我们就把它 migrate 到 Oracle 上去了。

avatar
g*l
22
SQL SERVER现在都快变LEGACY了,大公司都蜂拥ORACLE去了,我现在也被逼的去学
ORACLE。

【在 v*****r 的大作中提到】
: 大公司用 sybase 的还是不少吧.
: 想起了sybase 和 sqlserver 的老祖宗 Ingres. 头几年去一家公司,finance
: application 还是 Ingres based, 我帮着管过几天. 去参加了一个 Ingres 的 User
: group meeting, 到会的竟然有五十来家用户, 其中不乏一些大公司。 不过开完会回
: 来没多久我们就把它 migrate 到 Oracle 上去了。

avatar
B*g
23
你假如组织了吗?

【在 g***l 的大作中提到】
: SQL SERVER现在都快变LEGACY了,大公司都蜂拥ORACLE去了,我现在也被逼的去学
: ORACLE。

avatar
g*l
24
木有来,去看看

【在 B*****g 的大作中提到】
: 你假如组织了吗?
avatar
a9
25
我宁可count(*),哈哈。



【在 i****a 的大作中提到】
: 1. never use * in query ...
: Comment: Never say "never", 难道就没有碰到过需要 query 一个表所有columns 的
: 时候?我是经常见:-)
: Even if all columns are needed, avoid using select *. list all columns
: specifically. So when somebody adds a column to the table it doesn't break
: your program.
:
: efficient
: before

avatar
B*g
26
很多人认为count(1)比count(*)强


break
columns

【在 a9 的大作中提到】
: 我宁可count(*),哈哈。
:
: 的

avatar
a9
27
profiler一下就行了呗。

columns

【在 B*****g 的大作中提到】
: 很多人认为count(1)比count(*)强
:
: 的
: break
: columns

avatar
g*l
28
支持,经常用的还有IF EXISTS (SELECT TOP 1 1 FROM XXX)

【在 B*****g 的大作中提到】
: 很多人认为count(1)比count(*)强
:
: 的
: break
: columns

avatar
B*g
29
嘿嘿,反正oracle这些都是一样的。不过asktom上关于count(1)和count(*)骂战还是挺
有意思的。最基本的,都已经是cbo,起码也要看了ep再说。hoho

【在 g***l 的大作中提到】
: 支持,经常用的还有IF EXISTS (SELECT TOP 1 1 FROM XXX)
avatar
a*y
30
? 现在的公司不是会重用你吗?

【在 g***l 的大作中提到】
: 今天有个工作,大公司,PRINCIPAL SQL DEVELOPER,虽然不是喜欢的工作,我也去递
: 简历了,觉得自己比一般的DEVELOPER强。

avatar
B*g
31
跳一跳,工资职称涨一涨

【在 a***y 的大作中提到】
: ? 现在的公司不是会重用你吗?
avatar
g*l
32
该学的东西都学到了,除非老板去了,我做个小MANAGER,老板比我年纪还小,我还有
什么希望,跳是肯定的。

【在 a***y 的大作中提到】
: ? 现在的公司不是会重用你吗?
avatar
k*e
33
informix........
avatar
k*e
34
新sql server上也没区别了。
加一条:
use RANK 避免 self join

【在 B*****g 的大作中提到】
: 嘿嘿,反正oracle这些都是一样的。不过asktom上关于count(1)和count(*)骂战还是挺
: 有意思的。最基本的,都已经是cbo,起码也要看了ep再说。hoho

avatar
B*g
35
partition by! which will solve 90% some sql questions here

【在 k********e 的大作中提到】
: 新sql server上也没区别了。
: 加一条:
: use RANK 避免 self join

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。