| Author |
How to alter the data type of a field
|
|
|
| I want to change the filed type form nvarchar(5) to varchar(10)
There is no need to reserve the data in the filed.
How can I do with SQL command?
| |
| Kalen Delaney 2006-12-05, 12:12 am |
| Use the ALTER TABLE command:
ALTER TABLE my_table
ALTER COLUMN my_column varchar(10)
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"ad" <flying@wfes.tcc.edu.tw> wrote in message
news:umBJWlAGHHA.4652@TK2MSFTNGP04.phx.gbl...
>I want to change the filed type form nvarchar(5) to varchar(10)
> There is no need to reserve the data in the filed.
> How can I do with SQL command?
>
| |
|
| Thank,
Can I determinate if the data type varchar before ater it.
Like
if type(my_table.my_column) <>varchar(10)
ALTER TABLE my_table ALTER COLUMN my_column varchar(10)
"Kalen Delaney" < replies@public_newsg
roups.com> 撰寫於郵件新聞:O30Dz
nAGHHA.2128@TK2MSFTNGP03.phx.gbl...
> Use the ALTER TABLE command:
>
> ALTER TABLE my_table
> ALTER COLUMN my_column varchar(10)
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
>
> "ad" <flying@wfes.tcc.edu.tw> wrote in message
> news:umBJWlAGHHA.4652@TK2MSFTNGP04.phx.gbl...
>
>
| |
| Kalen Delaney 2006-12-05, 12:12 am |
| What version?
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"ad" <flying@wfes.tcc.edu.tw> wrote in message
news:OD2cMPBGHHA.5104@TK2MSFTNGP03.phx.gbl...
> Thank,
> Can I determinate if the data type varchar before ater it.
> Like
>
> if type(my_table.my_column) <>varchar(10)
> ALTER TABLE my_table ALTER COLUMN my_column varchar(10)
>
>
>
>
> "Kalen Delaney" < replies@public_newsg
roups.com>
> 撰寫於郵件新聞:O30Dz
nAGHHA.2128@TK2MSFTNGP03.phx.gbl...
>
>
| |
|
| my version is SQLServer 2005 Express
"Kalen Delaney" < replies@public_newsg
roups.com> 撰寫於郵件新聞:ORvLX
DCGHHA.4804@TK2MSFTNGP03.phx.gbl...
> What version?
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
>
> "ad" <flying@wfes.tcc.edu.tw> wrote in message
> news:OD2cMPBGHHA.5104@TK2MSFTNGP03.phx.gbl...
>
>
| |
| Kalen Delaney 2006-12-05, 5:16 am |
| This query returns all the datatypes and lengths for columns in a given
table. You should be able to figure out how to write your IF statement from
this information:
SELECT object_name(object_i
d) as [object_name], c.name as column_name,
t.name as type_name, c.max_length
FROM sys.types t join sys.columns c
ON t.user_type_id = c.system_type_id
WHERE object_name(object_i
d) = 'my_table'
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"ad" <flying@wfes.tcc.edu.tw> wrote in message
news:eoktgyCGHHA.2456@TK2MSFTNGP06.phx.gbl...
> my version is SQLServer 2005 Express
>
> "Kalen Delaney" < replies@public_newsg
roups.com>
> 撰寫於郵件新聞:ORvLX
DCGHHA.4804@TK2MSFTNGP03.phx.gbl...
>
>
|
|
|
|