Solved

How can I run a function on a database column?

Posted on 2016-09-06
5
35 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 48

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested Case statement 4 37
TSQL convert date to string 4 34
SQL Dump exec output to table 3 21
Getting invalid Syntax SQL. 3 14
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

790 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