Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

modify a field

Posted on 1998-12-13
3
Medium Priority
?
197 Views
Last Modified: 2010-03-19
Hi,
  I created a table "test" with a few fields some time ago. One of the field in this table is called "name" and the type was set to be char(20). For some reason, I need to extend this field to be char(40). Since the table has already got lots of data, I wonder what is the easieast way to do this modification while keep all the existing data. Do I HAVE TO create a new table and copy everything over and so on?
  Thanks for your time!

wyldsj
0
Comment
Question by:wyldsj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
spiridonov earned 160 total points
ID: 1092253
Yes,you'll have to recreate the table. There is no way in MS SQL to modify column of existing table.
Rename existing table, create new table under old name and then insert into new table from renamed.
0
 

Author Comment

by:wyldsj
ID: 1092254
how do I rename a table? Sorry but I am really new to SQL...

wyldsj
0
 
LVL 7

Expert Comment

by:spiridonov
ID: 1092255
Execute sp_rename old_name,new_name
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!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

715 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