April 15, 2010 at 5:26 pm
Dear Greater SQL Intellect,
Is there a way to update table data values.
I have this table:
CREATE TABLE ups_data
(UPS_Numberdecimal(2,1) NULL,
UPS_Modelvarchar(22)NULL,
Free_InputsintNULL,
Taken_Inputs_Sourcevarchar(19)NULL,
Attached_Devicevarchar(38)NULL,
Power_Ratingvarchar(21)NULL,
Model_Service_Tagvarchar(30)NULL)
I want to change the Model_Service_Tag data value from varchar(30) to varchar(50).
Is there a better way to go about this than drop the table -> make change -> create the table?
Perhaps I'm misunderstanding how to use the UPDATE transact sql command. From my gatherings, it seems to update the imported data...rather than the table data values.
Thanks.
Regards,
Mike G.
Seattle, WA
April 15, 2010 at 6:05 pm
Check out ALTER TABLE in BOL.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 15, 2010 at 6:07 pm
Like you said, UPDATE is used to update values within the table - it is a DML (Data Manipulation Language) command. What you want to do is modify the structure of the table -- you need to use DDL (Data Definition Language) commands.
Try the following:
ALTER TABLE ups_data
ALTER COLUMN Model_Service_Tag varchar(50)
Note that if the column you're changing is a primary key or has a constraint on it, you may have to drop any relationships or constraints that may exist before you make the change.
Also, if you're making the column SMALLER (e.g., to varchar(10) in your example), you could truncate data.
Rob Schripsema
Propack, Inc.
April 15, 2010 at 6:14 pm
Hello,
And there it is...
DML and DDL - it all makes sense now.
My apologies for such a novice inquiry...
Thank you for your replies.
Regards,
Mike G.
Seattle, WA
April 15, 2010 at 6:17 pm
No apologies necessary. We were all newbies once...
Rob Schripsema
Propack, Inc.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply