Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change the length of a DB varchar

10 views
Skip to first unread message

Cal Who

unread,
Jan 18, 2010, 4:33:26 PM1/18/10
to
I have an Sql Server 2005 Express DB containing the following table.

There is data in it.

Can I somehow change the description to 2000 characters while maintaining
the existing data?

Thanks

CREATE TABLE [Announcements] (

[id] [int] IDENTITY (1, 1) NOT NULL ,

[itemdate] [datetime] NOT NULL ,

[title] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[description] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]


SQLMenace

unread,
Jan 18, 2010, 4:55:02 PM1/18/10
to
use the ALTER command

alter table [Announcements] alter column [description] [varchar] (2000)


--check that it was changed
select * from INFORMATION_SCHEMA.COLUMNS
where table_name = 'Announcements'

Denis The SQL Menace
http://blogs.lessthandot.com/summary.php


" Cal Who" <Cal...@roadrunner.com> wrote in message
news:emBChXIm...@TK2MSFTNGP05.phx.gbl...

Cal Who

unread,
Jan 18, 2010, 6:33:57 PM1/18/10
to
Thanks, worked great.

Maybe this is an aspnet question - I don't know. Some of the code is shown
below.
When the size was 500 what happened was: the command to insert was just
ignored.
That is, there was no error message but the insertion never happened.
I wonder how I can notify the user it didn't happen.
Or check myself to see if the max has been exceeded

Thanks again
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ..snip

InsertCommand="INSERT INTO Announcements(itemdate, title, description)
VALUES (@itemdate, @title, @description)"

..snip

<InsertParameters>

<asp:Parameter Name="itemdate" Type="DateTime" />

<asp:Parameter Name="title" />

<asp:Parameter Name="description" />

<asp:Parameter Name="location" />

<asp:Parameter Name="id" />

</InsertParameters>


"SQLMenace" <sqlser...@NOTgmail.com> wrote in message
news:ufmoAlI...@TK2MSFTNGP02.phx.gbl...

Naomi

unread,
Jan 19, 2010, 8:41:50 PM1/19/10
to
On Jan 18, 5:33 pm, " Cal Who" <Cal...@roadrunner.com> wrote:
> Thanks, worked great.
>
> Maybe this is an aspnet question - I don't know. Some of the code is shown
> below.
> When the size was 500 what happened was: the command to insert was just
> ignored.
> That is, there was no error message but the insertion never happened.
> I wonder how I can notify the user it didn't happen.
> Or check myself to see if the max has been exceeded
>
> Thanks again
> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ..snip
>
> InsertCommand="INSERT INTO Announcements(itemdate, title, description)
> VALUES (@itemdate, @title, @description)"
>
> ..snip
>
> <InsertParameters>
>
> <asp:Parameter Name="itemdate" Type="DateTime" />
>
> <asp:Parameter Name="title" />
>
> <asp:Parameter Name="description" />
>
> <asp:Parameter Name="location" />
>
> <asp:Parameter Name="id" />
>
> </InsertParameters>
>
> "SQLMenace" <sqlserverc...@NOTgmail.com> wrote in message

>
> news:ufmoAlI...@TK2MSFTNGP02.phx.gbl...
>
>
>
> > use the ALTER command
>
> > alter table [Announcements] alter column [description] [varchar] (2000)
>
> > --check that it was changed
> > select * from INFORMATION_SCHEMA.COLUMNS
> > where table_name = 'Announcements'
>
> > Denis The SQL Menace
> >http://blogs.lessthandot.com/summary.php
>
> > "   Cal Who" <Cal...@roadrunner.com> wrote in message
> >news:emBChXIm...@TK2MSFTNGP05.phx.gbl...
> >> I have an Sql Server 2005 Express DB containing the following table.
>
> >> There is data in it.
>
> >> Can I somehow change the description to 2000 characters while maintaining
> >> the existing data?
>
> >> Thanks
>
> >> CREATE TABLE [Announcements] (
>
> >> [id] [int] IDENTITY (1, 1) NOT NULL ,
>
> >> [itemdate] [datetime] NOT NULL ,
>
> >> [title] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>
> >> [description] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
>
> >> ) ON [PRIMARY]- Hide quoted text -
>
> - Show quoted text -

Why do you have some extra parameters that are not used in your Insert
statement? It also may help to explicitly define type and size of each
parameter.

Cal Who

unread,
Jan 20, 2010, 11:47:50 AM1/20/10
to

Because I'm strugling here to know what to do.
I guess you mean location and id
Is that right?

I notice that the insert command does not include id but the CREATE TABLE
does. Does that seem like a posible error to you?


>It also may help to explicitly define type and size of each
> parameter.

How is this done?


Thanks very much


0 new messages