[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 49
  • Last Modified:

How can I run a function on a database column?

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
earwig75
Asked:
earwig75
  • 2
  • 2
2 Solutions
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Should be an UPDATE then. Something like this:
UPDATE TableName
SET ColumnName = MyFunction(ColumnName)

Open in new window

0
 
Scott PletcherSenior DBACommented:
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
 
earwig75Author Commented:
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
 
Scott PletcherSenior DBACommented:
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
 
earwig75Author Commented:
Thank you for the help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now