The sum of all SQL Server matter that exist,
and the space in which all SQL Server events
occur or could occur.
Welcome to SQL Server Universe.com Sign in | Join | Help
in
Home SS SLUG Forums Articles Photos Downloads

TIME OUT

Last post 02-14-2008, 10:25 by G.R.Preethiviraj Kulasingham. 2 replies.
Sort Posts: Previous
  • TIME OUT

     02-11-2008, 16:59

    • Joined on 08-17-2007
    • Posts 7
    • Points 0
    • Top 25 Contributor

    Hi 

    I have a table in my database (SQL 2000) which has about 250000 records. I want to add a new field with a defulat value (with out null) to this table. but when i am going to save this , it gives a time out. what could be the reason for this ?. I tryed with a table with less record than this, it was ok. Is it a problem with more records ?

    Thanks

    wimal

  • Re: TIME OUT

     02-11-2008, 21:31

    • Joined on 11-22-2006
    • Colombo, Sri Lanka
    • Posts 102
    • Points 0
    • Top 10 Contributor
      Male
    Hi Wimal,

    It is better to use TSQL to alter a table than Enterprise Manager. Use ALTER TABLE statement for adding the new column with default value. I think that you get the time-out error because EM drops and recreates the table that leads to time-out error.

  • Re: TIME OUT

     02-14-2008, 10:25

    • Joined on 04-02-2007
    • Colombo
    • Posts 28
    • Points 0
    • Top 10 Contributor
      Male

    For the benifits of the users I am sending this post,

    This type of error can occur in any server product.  The client sends a reqest and waits for the response.  If the response if not received within the time specified you will receive a timeout error. For your case it happens because of the size of the table.
     
    As a simple solution you can increase the query timeout value.  If you specify the value to 0 it will wait indefinitly (until the server  responds back)
     
    if you are using a non dev system where performance is an issue re-write your code slightly differently.  Dont add the new column with NOT NULL clause.  create it will NULL.  then update witht he default value for small chuck of data.  Finally you can add the default value if  you want.
     
    This is a sample code.
     
    ALTER TABLE <table1>  ADD <NewColumn> varchar (50) NULL
     
    DECLARE @Min int, @Max int, @Current int
    SELECT @Min = MIN(TableID), @Max= MAX(@TableID) from <table1> 
    SET @Current = @Min
    WHILE @Current <= @Max
    BEGIN
          UPDATE <Table1> SET <newColumn> = 'DEfault Value' WHERE TableID >=@Current AND TAbleID <@Current+1000
         SET @Current = @Current+1000
    END
     

     

     


    G.R.Preethiviraj Kulasingham MCITP: DBA
    http://preethiviraj.blogspot.com/
    Plan Your Work and Work Your Plan!
View as RSS news feed in XML

(Best viewed with a resolution of more than 1024 * 768)

Powered by Community Server, by Telligent Systems