Solved

How can I run a function on a database column?

Posted on 2016-09-06
5
37 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 49

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert varchar UTC to human datetime 1 38
MS SQL Server connect issues 4 37
Database maintenance 36 98
Not listening to where 1 9
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

679 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