Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

modify a field

Posted on 1998-12-13
3
Medium Priority
?
199 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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Victor 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:Victor Spiridonov
ID: 1092255
Execute sp_rename old_name,new_name
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

916 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