August 21, 2002 at 8:59 am
I wnat to modify the datatypes of several columns in a table. Can someone help me with the syntax?
Thanks!
August 21, 2002 at 9:28 am
Try something like this. Hope this helps.
create table a (
col1 int)
select column_name , data_type from information_schema.columns
where table_name = 'a'
-- change col1 from int to char(10)
alter table a
alter column col1 char(10)
select column_name, data_type from information_schema.columns
where table_name = 'a'
drop table a
-------------------------
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
August 21, 2002 at 9:31 am
Use something like this:
ALTER TABLE tablename ALTER COLUMN columnname datatype
GO
simply replace the word datatype with the datatype you want to change the column datatype to.
An example would be to change the data type for a column called NeedsMaint in a table called Components to bit:
ALTER TABLE Components ALTER COLUMN NeedsMaint bit
GO
Robert Marda
SQL Server will deliver its data any way you want it
when you give your SQL Programmer enough developing time.
Robert W. Marda
Billing and OSS Specialist - SQL Programmer
MCL Systems
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply