You must Sign In to post a response.
  • Category: SQL Server

    How to update column data


    Are you trying to update single column of your database table but confuse how to do? Read this thread and get detailed information.



    How to update a single column data while doing updation?
  • #732297
    Hi Namrata,

    Update Your_table_Name Set Your_Column_Name='' where Your_Column_Name=''

    eg:-

    Update Employee Set Name='Charles' where id=1001


    Regards,
    Sri

  • #732299
    Thanx Sir

  • #732300
    Hi Namrata,

    Try something like below to achieve your goal.


    update table_name set col1='hello'
    where conditions

    This is common syantax, if you search in google you may get no.of results, why can't you are not search in google. First off all try to search by your self that is good practise to learn any technology.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #732313
    Hi Namratha,
    This is one of the basic commands of SQL.

    First try to go through the basics of SQL statements and try few examples searching them on google.

    Any way the solution provided by the above members are apt.

    Here is one of the best links for the starters to learn SQL:

    http://www.w3schools.com/sql/sql_intro.asp

    Hope it helps you and best of luck

    Thanks & Regards,
    srikanth,
    Software Engineer.
    @DOTNET-SPIDERS ROCK@

  • #732343
    You can use this statement to update column data in SQL Server
    With Cte As (select Row_number() Over(partition By Col1 Order By Col1 Asc)as Row ,col1 From Tablename)
    Update Cte Set Col1=a.col1 From Table2 A Where Cte.row=a.col1;

  • #732362
    Hi,

    Using update query you can update the specific column values with the help of primary key value.

    You can try the following code.

    SqlConnection con = new SqlConnection("Data Source=datasourcename;Initial Catalog=databasename; user id=username; password=passwordvalue");
    con.Open();
    SqlCommand com = new SqlCommand("update table set columname='"+columnvalue + "' where primarykeycolumnname='" + columnvalue + "'", con);
    int result = com.ExecuteNonQuery();
    //ExecuteNonquery will return either one or zero integer based on the query, if it is affected it will return one or else it will return zero
    com.Dispose();
    con.Dispose();
    return result;

    Hope it will be useful.

    Regards,
    T.N. THEAAVARAAJ
    Senior Software Engineer,
    Microsoft Certified Technology Specialist.
    Email:devabe2005@gmail.com

  • #735444
    update test set productame='fdfd' where productid=10001


    hope this i will help...


  • Sign In to post your comments