Said Salomon Unitrin Direct Insurance T-SQL Avoiding cursors Said Salomon
I have over 25 year experience IT. I have a vast array of abilities in the field in the areas of Network, Desktop Support, DBA, Staff Project Management, Application Software Development, Business Analysis and Quality Assurance. I have Microsoft certifications as MCTS, MCPS, and MCNPS, and multiple certifications from the Insurance Institute of America. Currently I am a DBA at Unitrin Direct Insurance.
A cursor is pointer into a rowset Allows a single row at a time to be processed DECLARE c1 CURSOR READ_ONLY
Most programmers have a process a row mindset (read a record process a record) Complex operations need to be done on each row
SQL is a rowset system Performance (system impact) Slower than using rowset logic Creates locks on the table more memory to accomplish the same task require more code to write
Use a case statement Multiple rowset operations Use a temp table with IDENTITY Using User Defined Functions use a common-table expression (CTE)
Demo
Avoiding cursors with SQL Server SQL Cursors - how to avoid them SQL Server 2008, Dev Edition My Twitter SaidSalomon