Results 1 to 6 of 6
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DELETE all record in sql table (2005)

    how to delete all record in sql table?
    This is my conn and code :

    Sub ADO_ACCESS_To_SQLServer()

    'DA ACCESS A SQL

    Set rsSql = New ADODB.Recordset
    Set CnSql = New ADODB.Connection

    ServerName = "CL151F4500SQLEXPRESS"
    DatabaseName = "MASTER"
    TableName = "SOSPESI"
    UserID = ""
    Password = ""

    CnSql.Open "Driver={SQL Server};Server=" & ServerName & ";Database=" & DatabaseName & _
    ";Uid=" & UserID & ";Pwd=" & Password & ";"

    rsSql.Open TableName, CnSql, adOpenKeyset, adLockOptimistic

    SQL = "SELECT * FROM SOSPESI"
    CnSql.Execute (SQL)
    SQL = "truncate table SOSPESI"
    CnSql.Execute (SQL)
    ........

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DELETE all record in sql table (2005)

    You don't need to select records from a table in order to delete them. The lines

    rsSql.Open TableName, CnSql, adOpenKeyset, adLockOptimistic
    SQL = "SELECT * FROM SOSPESI"
    CnSql.Execute (SQL)

    are superfluous here.

    To delete all records from the table SOSPESI, you can either execute the SQL statement

    "DELETE * FROM SOSPESI"

    or

    "TRUNCATE TABLE SOSPESI"

    The latter one is faster and more efficient.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DELETE all record in sql table (2005)

    tks.... always for explain
    i use truncate...

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DELETE all record in sql table (2005)

    DUBT....but after TRUNCATE sql is needed to refresh table or batabase? if yes wth is the statement?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: DELETE all record in sql table (2005)

    Not as far as I know.

  6. #6
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DELETE all record in sql table (2005)

    ok...
    Tks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •