Solved

How can I run a function on a database column?

Posted on 2016-09-06
5
32 Views
Last Modified: 2016-09-07
I have a function that removes all special characters etc on insert/update. I want to run this function on an existing column so it will go through every entry in the table and remove the special characters on a specific column. Can someone tell me how I can accomplish this?
Thank you!
0
Comment
Question by:earwig75
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 41786178
Should be an UPDATE then. Something like this:
UPDATE TableName
SET ColumnName = MyFunction(ColumnName)

Open in new window

0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41786274
How large is the table?  Do you have sufficient time and log space to handle changing all rows in a single UPDATE?  Can you afford to have the table unavailable to any other task until the UPDATE completes?
0
 

Author Comment

by:earwig75
ID: 41786388
There are 380,000. I've never done this before so I'm not sure how long it would take. Do you have any idea of an estimate? Would it take longer than 5 minutes? Thanks.
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 250 total points
ID: 41786424
Depends on server speed and how long each column is.  If the data is 100 bytes or less, I'd expect not.  If it's 8000 bytes or more, I'd expect it would take more than 5 minutes.

Also, you need to pre-allocate enough log space to handle the update.  If the log has to grow dynamically, the entire db pauses while the log is extended (and, as a secondary concern with that, you can physically fragment the log file, somewhat slowing future processing).
0
 

Author Comment

by:earwig75
ID: 41788261
Thank you for the help.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL query to generate xml 4 34
Can > be used for a Text field 6 44
T-SQL:  Collapsing 9 25
SQL Query Help Top 1 and Distinct? 6 26
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question