Home > Ask the SQL Server Experts > Joe Toscano - Integration Services/Development Questions & Answers > Stored procedure practices in SQL Server
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Stored procedure practices in SQL Server

Joe Toscano EXPERT RESPONSE FROM: Joe Toscano

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 12 October 2006
How can I debug stored procedures and trap errors in a stored procedure? Can you give me an example?

How can I call a stored procedure from functions?

How can I find duplicate values in a table?


>
EXPERT RESPONSE
How you debug and handle errors in your stored procedures really depends on which version of SQL Server you are working with. SQL 2005 supports structured error handling with TRY … CATCH. Prior version require that you use @@ERROR and @@ROWCOUNT after each critical inser/update or delete. You may consider looking at two tips I wrote: "How to Debug your Transact-SQL Stored Procedures" and "Structure Error Handling in SQL 2005." Fine these and more tips on SQL Server Stored procedures here.

There are several ways to delete duplicate rows from a table. This is the easiest way of de-duplicating a table, and is at its best with fairly small rowsets, and where all the columns in a table are duplicates. We simply run a SELECT DISTINCT on the offending table, storing the results in a temporary table, then delete the contents of the permanent table and re-populate it from the temporary one. While this may be the simplest way, you may have some space issue if you are working with millions of rows. Derived tables and correlated subqueries can also be used.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
SQL Server stored procedures
How to use SQL Server 2008 hierarchyid data type
SQL and SQL Server Tutorial and Reference Guide
SQL Server stored procedures tutorial: Write, tune and get examples
Check SQL Server database and log file size with this stored procedure
SQL Server source code analysis and management adds database security
Configure SQL Server Service Broker for sending stored procedure data
Find size of SQL Server tables and other objects with stored procedure
Track changes to SQL Server 2000 and 2005 with one simple utility
Troubleshoot SQL Server 2005 temporary table performance problems
Use SQL Profiler to find long running stored procedures and commands

Joe Toscano - Integration Services/Development
How to convert DTS packages to SSIS and overwrite data
How to migrate DTS to SSIS and deploy SSIS packages
Query to search text in old DTS packages in SQL Server?
Error importing Excel data to SSIS in SQL Server 2005
Delete .bak files automatically with CLR
DTS package designed to overwrite extract.xls
Displaying a SQL Server database report in Excel
Call triggers in a stored procedure
SQL Server permission to create jobs and schedules in SSIS
Problems with structured exception handling

Microsoft SQL Server
SQL Server errors, failures and other problems fixed from the trenches
SQL Server consolidation: Why it's an optimization technique
Can you shrink your SQL Server database to death?
Using SQL Server datetime functions GETDATE, DATENAME and DATEPART
Tuning SQL Server performance via memory and CPU processing
Get SQL Server log shipping functionality without Enterprise Edition
SQL Server 2008 backup compression pros and cons
How to use SQL Server 2008 hierarchyid data type
Tuning SQL Server performance via disk arrays and disk partitioning
Should you upgrade to SQL Server 2005 or SQL Server 2008?

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
library  (SearchSQLServer.com)
trigger  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2005 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts