What Is The Best Practice To Change A Column's Data Type In A Very Big Table?

Dec 11, 2007



Hi All,

I am using SQL Server 2000 Enterprise Edition fully patched. Database is in Simple Recovery mode.

I need to change a column's data type from "int(4)" to "smallint(2)". I know for sure that there will be no data (precision) lost, because I know the possible values that this column could have.

My problem is that the table I am dealing with has 600,000,000 records in it. I dropped all indexes before I tried to alter the table. But still it is taking forever and filling up my 280GB disk with transaction log file.

I know that in Oracle, if I want I can turn off logging and do these kind of modifications relatively faster.

I was wondering if there is a way of disabling logging before running this alter command.

What is the best practice to handle a situation of this sort?

I appreciate your help.

Thanks in advance,
Sinan Topuz

View 3 Replies


ADVERTISEMENT

Update On Large Table - Change Data Type For Text Column

Dec 10, 2014

I need to update a large table, about 55 million rows, without filling the transaction log, in the shortest time as possible. The goal is to alter the table and change the data type for Text column from VARCHAR(7900) to NVARCHAR(MAX).

Since I cannot do it with an ALTER TABLE statement (it would fill up the transaction log) I'm thinking to:

- rename column Text in Text_OLD
- add Text column of type NVARCHAR(MAX)
- copy values in batches from Text_OLD to Text

The table is defined like:

create table DATATEXT(
rID INTEGER NOT NULL,
sID INTEGER NOT NULL,
pID INTEGER NOT NULL,
cID INTEGER NOT NULL,
err TINYINT NOT NULL,

[Code] ....

I've thought about a stored procedure doing this but how to copy values in batch from Text_OLD to Text.

The code I would start with (doing just this part) is the following, but maybe there are more efficient ways to do it, or at least there's a better way to select @startSeq in the WHILE loop (avoiding to select a bunch of 100000 sequences and later selecting the max).

declare @startSeq timestamp
declare @lastSeq timestamp
select @lastSeq = MAX(sequence) from [DATATEXT] where [Text] is null
select @startSeq = MIN(Sequence) FROM [DATATEXT] where [Text]is null
BEGIN TRANSACTION T1
WHILE @startSeq < @lastSeq

[Code] ....

View 1 Replies View Related

SQL Change Column Data Type

Aug 20, 2007

How do I programatically  change a column (say username) in a table (say tblusers) from varchar(25) to varchar(100)I am looking for something likealter tblusers set username as  varchar(100) I know the above statement in nonsensical but it conveys the idea. 

View 3 Replies View Related

Sql Script To Change Type Of Column With Data

Sep 29, 2007

I have a table say Friend which has a column "IsSingle VARCHAR(10)" and this column has values like yes or No
Now I want to change type of column IsSingle from VARCHAR to BIT, if I try to do it manaually SQL throws error that cannot convert yes to bit etc.
I know that we can write a script to do this task but i dont know how ?
Any pointers,links, suggestions will help me to start with.
 
Thanks for your help. 
 
 

View 2 Replies View Related

Change Data In Column Of Table

Feb 24, 2014

How to modify/change data that is in a SQL table column. Here is what I need or have

I have 2 tables, Table 1 and Table 2, within those 2 tables there is 1 Column that has the same column heading aswell as data within,(I will call it the serial_number column) there is also a 2nd column that is labeled the Same in both tables, I would like to be able to update the Values in the 2nd column of table 1 with the values from table 2 column 3, using the Serial_number column as my matching reference between the 2, the data is not in the same order between the 2 Tables,

More or less I need to set the value of table 1/column 2 to match table 2/column 3, where the serial_numbers are the same in both tables serial_number columns, the data being changed is set as Small int...

View 3 Replies View Related

Change Value Of Column Mimetype In Table Data

Aug 23, 2013

I have two tables:

dtr
dataid........Subtype
data
docid....mimetype

I need to change the value of column mimetype in table data, but only for these entries which have the value 144 in column "Subtype" in table dtr.

Here is my sql:

with cte as (
select
DataID,
SubType,
MimeType
from dtr A1, data A2
where A1.dataid=A2.Docid And A1.Subtype='144'
AND
A2.mimetype='application/news-message-id'
)
update cte set MimeType = 'application/x-outlook-msg'

I've tested it and it works. Do you see any problems with this SQL?

As updates are risky I'll do a database backup. Is it possible to get all changed entries so that I can track my update, because I don't have a report about the changes? Maybe that everythin is transferred to an output file?

View 4 Replies View Related

Query Data Type Of Column In DB Table

Aug 14, 2006

Hi All
I want to retrieve the data type of table column and validate the input data whether same as data type of table column before insert into database. Any suggestion?
I use asp.net + msde
 
Thank you.

View 6 Replies View Related

Create Table: Want A Column With Money Data Type

Dec 14, 2007

Hi all!

I want to create a table. One of the columns should be in the data type MONEY with two digits on the right side of the decimal point.
How is that possible?

Thanks a lot and greetings from vienna

landau

View 2 Replies View Related

Can A Column Data Type Be Changed On A Replicated Table?

Dec 21, 2006

On sqlserver 2000 transactional replication:

How would I best go about changing a published table's column from smallint to int? I could not find anything about it in BOL or MS.com. I do not think EM/Replication Properties allows the change. I suspect I have to run "Alter Table/Column" on the Publisher and each Subscriber the old-fashioned way. Is that true?



Thanks!

View 3 Replies View Related

Change Chart Type Dynamically From Column To Line Graph??

May 1, 2006

I am developing several charts with column type and sub type as stacked. There is a requirement from the users that they want an option to choose the type of chart.

Is it possible to change chart type dynamically from say Column type to Line type based on user option in front-end?

Any help will be appreciated.

Thanks in advance !!

View 5 Replies View Related

Custom Transform Component, Change Type Or Add Output Column

Jun 26, 2006

Would anyone happen to have any pointers or know of any good code examples to either programmatically change the type of an input column when it is passed through the component, or add a new column to the output? I am extracting data from an Oracle database which is in Julian date format (represented within SSIS as a DT_NUMERIC column) and I need to to either transform the input column holding it into a date column, or to dynamically add a new output column holding the transformed data.

Many thanks

View 1 Replies View Related

Bulk Insert Task Failing On Data Type Conversion For A Destination Column Of Type Bit

Jul 6, 2006

I am trying to use the Bulk Insert Task to load from a csv file. My final column is a bit that is nullable. My file is an ID column that is int, a date column that is mm/dd/yyy, then 20 columns that are real, and a final column that is bit. I've tried various combinations of codepage and datafiletype on my task component. When I have RAW with Char, I get the error included below. If I change to RAW/Native or codepage 1252, I don't have an issue with the bit; however, errors start generating on the ID and date columns.

I have tried various data type settings on my flat file connection, too. I have tried DT_BOOL and the integer datatypes. Nothing seems to work.

I hope someone can help me work through this.

Thanks in advance,

SK



SSIS package "Package3.dtsx" starting.

Error: 0xC002F304 at Bulk Insert Task, Bulk Insert Task: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.The bulk load failed. The column is too long in the data file for row 1, column 24. Verify that the field terminator and row terminator are specified correctly.Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 23 (cancelled).".

Error: 0xC002F304 at Bulk Insert Task 1, Bulk Insert Task: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.The bulk load failed. The column is too long in the data file for row 1, column 24. Verify that the field terminator and row terminator are specified correctly.Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 23 (cancelled).".

Task failed: Bulk Insert Task 1

Task failed: Bulk Insert Task

Warning: 0x80019002 at Package3: The Execution method succeeded, but the number of errors raised (2) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

SSIS package "Package3.dtsx" finished: Failure.

View 5 Replies View Related

SQL Data Type Change

Jun 23, 2005

I'm trying to compare 2 field in 2 different databases and one is varchar and one is numeric. Is there anyway I can tell SQL to treat the one thats numeric as varchar or convert numeric to varchar for the comparison string... I'm trying to run the following in query anaylzer:update crcwebauth.dbo.deviationmaster set ldate = (select max(qvdate) from crcbrio.dbo.invoice_tbl where dnumber = qvqote)It gives me error:Server: Msg 8114, Level 16, State 5, Line 1Error converting data type varchar to numeric.The DNumber field is numeric and the qvqote is a char field...

View 1 Replies View Related

Change Data Type

Oct 6, 2005

I received a db2 data file that I converted to MS-Access. From Access Iran the upsize wizard to put the tabel in SQL. It put the table in okbut all the data types are nvarchar. I have a couple of the fields thatare cureny and some that are numeric.I need to change the data types from nvarchar to numeric type fields. Iam new to SQL so I do not know all the commands. How do I change thedata type?Michael Charney*** Sent via Developersdex http://www.developersdex.com ***

View 1 Replies View Related

Change Data Type During INSERT INTO ?

Jul 23, 2005

I'm doing a data conversion project, moving data from one SQL app toanother.I'm using INSERT INTO with Select and have the syntax correct. But whenexecuting the script I get:Server: Msg 8114, Level 16, State 5, Line 1Error converting data type varchar to float.Is it possible to change the data type during the INSERT INTO statement?Thanks

View 3 Replies View Related

Data Type Change In SQL View

Jul 20, 2005

I've created a SQL View in SQL 2000 using a table that has columnsdefined as Numeric data type. In the view, I am grouping and summing.When I link the view via ODBC to Access, all of the data types arechanged to text. If I link the original table which the views arecreated from to Access, the data types are correct. So this problemobviously happens when I change the view to Group. Is there a wayaround this? I want the data types to be correct in Access when Ilink to the views.thanks,jim

View 1 Replies View Related

Change Data Type Of Variable

Oct 3, 2007



Is there anyway to change the data type of a variable while in an expression?
My problem is I am trying to compare a variable w/ a string data type to a variable w/ an object data type. I would change the data type of the variable from object to string but if I do that my sql task fails when it tries to write a value to that variable. The variable w/ the object data type is the result of an openquery sql stmnt. So I guess there are two ways around my problem.

1. Change data type of variable while in an expression..ie flow constriant
or
2. Change data type of vraiable from object to string and still get the openquery result to work.

Any help???
Thanks !!

View 4 Replies View Related

Change Data Type In Many Tables In One Go

May 14, 2008



Hi.

I have tables (they are empty and there are no constraints) with columns typed as varchar. In a database I want to change the type of all the varchar columns in all the tables from varchar to nvarchar. What's the best way to do it? Can you suggest code?

I know that to get all the relevant columns I would issue a query like this

select *
from information_schema.columns
where data_type = 'varchar'

Then I would use a cursor... And that's exactly what I would not like to do. Is there any other way?

Thanx.
Darek

View 3 Replies View Related

Change The Column_Name – Data Type With A Query? Possible?

Apr 6, 2004

Hi everyone,

I’ve got a small question: Is it possible to change the Column_Name – Data Type from a SQL table with a query?

I want to do this with a query.

The Data Type ‘ntext’ must be changed to ‘text’

Thanks in advance!

View 4 Replies View Related

Is It Possible To Change The Data Type During An Sql Update Statement?

Jun 13, 2007

Hello,



I have a SQL update statement that updates some user names, however, the user names exceed the length of the data type. Currently, for the column username the data type is set to nvarchar (8).



How can I change that to nvarchar(10) in a SQL Update statement?



Thanks in advance.

View 9 Replies View Related

DB Design :: Cannot Change Datetime Default Data Type

Nov 17, 2015

Ilve install sql server 2012 in my pc and i want to change datetime default format. How can i do this and please i dont want to take the result from select convert() or select cast or something like this. I ve want to take the format i want writing query select datecolumn from table. 

Now the format i have is: 2015-11-16 09:04:00.000

And i want this format: 16.11.2015 09:04:00

Is any way to convert automaticaly by select only column? or can i change at all once? or must write function to when i select the column can change automatic ? or another thing, i ve see in column properties something like formula. In computed column specification in formula i wrote this: 

((CONVERT([varchar](10),getdate(),(104))+' ')+CONVERT([varchar](10),getdate(),(108)))

And I take the format i want automaticaly but i get the current date for all rows and i cant edit or insert that column anymore. So, how to change the format of date time but no from select query.

View 4 Replies View Related

Transact SQL :: Change Data Type In All Fields In Database

Sep 25, 2015

I want change all field in database to new datatype.I want change data from Small Integer to Integer but there are the relation in each table.

View 3 Replies View Related

Urgent - Change Data Type In Merge Replication Setup

Jul 7, 2004

Hi

I am new to Sql server and had just finished the MErge Replication setup on one of the PRoduction server. Today I got the request to change one of the Datatype of one the Published Article. Please help as what are the correct step to make it happen. Is there any production downtime required and if yes , then how much.

Thanks in Advance
Sanjay

View 1 Replies View Related

How Can I Change The Data Type Of The Parameter For The Deployed Stored Procedure ??

Jan 11, 2006

Hi
 
I have Try to Create Stored Procedure in C# with the following structure
 
[Microsoft.SqlServer.Server.SqlProcedure]
public static void sp_AddImage(Guid ImageID, string ImageFileName, byte[] Image)
{
       
}
 
But  when I try to deploy that SP to SQL Server Express  , The SP Parameters become in the following Stature
 
@ImageID uniqueidentifier
@ImageFileName nvarchar(4000)
@Image varbinary(8000)
 
But I don€™t want that Data types .. I want it to be in the following format
 
@ImageID uniqueidentifier
@ImageFileName nText
@Image Image
 
 
How Can I Control the data type for each parameter ??
Or
How Can I Change the data type of the parameter for the Deployed Stored Procedure ??
Or
How Can I defined the new Data type ??
 
Or
 
What's the solution to this problem ??
 
Note : I get Error when I try to use Alert Statement to change the parameter Data type for the SP
 
ALTER PROCEDURE [dbo].[sp_AddImage]
      @ImageID [uniqueidentifier],
      @ImageFileName nText,
      @Image Image
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [DatabaseAndImages].[StoredProcedures].[sp_AddImage]
GO
 
And thanks with my best regarding
Fraas

View 7 Replies View Related

How To Create A System Type Table/ Change User Table To System Table.

May 23, 2007

Is there any Posibility to change a User Table to System Table.

How to create one system table.

I am in Big mess that One of the Table I am using is in System Type.

I cant Index the same. Is there any Mistake we can change a user table to system table.....

View 9 Replies View Related

Creating A Stored Procedure That Will Summarize Data In A Table Into A Table Reflecting Period Data Using An Array Type Field

Sep 20, 2007

I am attempting to create a stored procedure that will launch at report runtime to summarize data in a table into a table that will reflect period data using an array type field. I know how to execute one line but I am not sure how to run the script so that it not only summarizes the data below but also creates and drops the table.

Any help would be greatly appreciated.

Current Table

Project | Task | Category | Fiscal Year | Fiscal Month | Total Hours
---------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 2007 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2007 | 02 | 20
Proj 1 | Task 1 | Cat 3 | 2007 | 03 | 35
Proj 1 | Task 1 | Cat 1 | 2008 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2008 | 02 | 40
Proj 1 | Task 1 | Cat 3 | 2008 | 03 | 40

Proposed Table

Project | Task | Category | Fiscal Month 01 | Fiscal Month 02 | Fiscal Month 03 | Fiscal Year
---------------------------------------------------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2007
Proj 1 | Task 1 | Cat 2 | 0 | 20 | 0 | 2007Proj 1 | Task 1 | Cat 3 | 0 | 0 | 35 | 2007
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2008

Proj 1 | Task 1 | Cat 2 | 0 | 40 | 0 | 2008
Proj 1 | Task 1 | Cat 3 | 0 | 0 | 40 | 2008

Thanks,
Mike Misera

View 6 Replies View Related

TSQL - Using ALTER TABLE - ALTER COLUMN To Modify Column Type / Set Identity Column

Sep 7, 2007

Hi guys,
If I have a temporary table called #CTE
With the columns
[Account]
[Name]
[RowID Table Level]
[RowID Data Level]
and I need to change the column type for the columns:
[RowID Table Level]
[RowID Data Level]
to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time.
What will be the right syntax using SQL SERVER 2000?

I am trying to solve the question in the link below:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1

Thanks in advance,
Aldo.

I have tried the code below, but getting syntax error...



ALTER TABLE #CTE
ALTER COLUMN
[RowID Table Level] INT IDENTITY(1,1),
[RowID Data Level] INT;


I have also tried:

ALTER TABLE #CTE
MODIFY
[RowID Table Level] INT IDENTITY(1,1),
[RowID Data Level] INT;







View 18 Replies View Related

Integration Services :: How To Change SSIS Packages Deployed To MSDB - Image Data Type

Jun 22, 2014

Is there a way to change an image data type? I want to make a change to some deployed SQL 2008 SSIS deployed packages. I have a TSQL SELECT that searches the packages for a string. But I would like to be able to change a string. I have googled it but cannot find anything.

View 5 Replies View Related

Change Row To Column In A Table

Oct 19, 2001

Hi, guru,

How can I Change all rows into columns from one table? what method can make it easy?

Thank you very much

Tony

View 1 Replies View Related

System.Data.SqlClient.SqlException: Syntax Error Converting The Varchar Value 'V' To A Column Of Data Type Int

Aug 31, 2006

 I am using  a stored procedure which returns a value of charecter datatype 'V' to the calling program.I am getting an sql exception System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'V' to a column of data type inti didnot define any int datatype in my tablethis is my codeSqlCommand com = new SqlCommand("StoredProcedure4", connection);com.CommandType = CommandType.StoredProcedure;  SqlParameter p1 = com.Parameters.Add("@uname", SqlDbType.NVarChar);SqlParameter p2 = com.Parameters.Add("@opwd", SqlDbType.NVarChar);SqlParameter p3 = com.Parameters.Add("@role", SqlDbType.NVarChar);p3.Direction = ParameterDirection.ReturnValue;p1.Value = username.Text.Trim();p2.Value = password.Text.Trim();com.ExecuteReader();lblerror2.Text = (string)(com.Parameters["@role"].Value); can your figure out what is the error ? Is it a coding error or error of the databse

View 3 Replies View Related

How To Change Column Data As Row

Oct 28, 2007

hi

I have a table like this




Username

Clicks

Impressions

Download


User1

12

23

43


User2

34

33

59


User3

39

88

77


User4

34

43

43
need to change the table like this







User1

User2

User3

User4


clicks

12

42

43

43


Impressions

43

43

43

43


download

43

43

43

43
Thanks
Ezhil

View 4 Replies View Related

Change Capitalization In Sql Table Column

Apr 10, 2007

I have some data that was entered in the DB in ALL CAPS. I would like to reformat all the rows so that it follows the normal "Capitalization". What is the best way to do this? Shoud I create a console application to accomplish this or is there some way to do it natively in sql server 2005.

View 2 Replies View Related

Change Table Column Width

Mar 14, 2000

I know we could change the data type or width of a table column in SQl 7 database, but I am not certain if this column is a primary key. Can we change a primary key column width? If we can, how about this column as a foreign key in another table? Will it be automatically updated to the same width? Thanks in advance for your input.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved