Solved

modify a field

Posted on 1998-12-13
3
193 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 40 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

615 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