[Show all top banners]

xbox
Replies to this thread:

More by xbox
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 SQL
[VIEWED 2609 TIMES]
SAVE! for ease of future access.
Posted on 07-13-07 1:15 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hi all,

I have to do small thing is SQL server. rename the existing column name and update the character of that column but all the values of column in it. for eg

Number Code Amount
1001 W 123.45
1001 A 123.45
1002 B 78.90
1003 C 86753.09

I need to change Number into ID and keep all the values in it. also right now number has character int(10) which needs to change into int(6). I know i can do this by right clicking that column and clicking design table and changing everything out there but the thing is i need this in script. Can somebody help me to do this in simplest way.
 
Posted on 07-13-07 1:58 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

exec SP_Rename 'tablename.oldcolumnname','newcolumname','Column'

this proc works fine but can we write our own script
 
Posted on 07-13-07 2:07 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

try this one to change the data type

ALTER TABLE
MODIFY (Number int(6) NOT NULL );



Try this one to rename the column Name

EXEC sp_rename
@objname = 'table_name.old_column_name',
@newname = 'new_column_name',
@objtype = 'COLUMN'
 
Posted on 07-13-07 2:09 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

correction on first one

ALTER TABLE tableName
MODIFY (Number int(6) NOT NULL );
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
What are your first memories of when Nepal Television Began?
निगुरो थाहा छ ??
TPS Re-registration case still pending ..
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
मन भित्र को पत्रै पत्र!
TPS Work Permit/How long your took?
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Breathe in. Breathe out.
Guess how many vaccines a one year old baby is given
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
चितवनको होस्टलमा १३ वर्षीया शालिन पोखरेल झुण्डिएको अवस्था - बलात्कार पछि हत्याको शंका - होस्टेलहरु असुरक्षित
They are openly permitting undocumented immigrants to participate in federal elections in Arizona now.
Driver license help ASAP sathiharu
Why Americans reverse park?
Travelling to Nepal - TPS AP- PASSPORT
Nepali doctors future black or white usa ?
Doctors dying suddenly or unexpectedly since the rollout of COVID-19 vaccines
lost $3500 on penny stocks !!!
Nas and The Bokas: Coming to a Night Club near you
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters