5

I am using R on Linux/Ubuntu machine. I am using RMySQL package to connect to a MySQL database

I need to drop a table from that database and would like to know a suitable command. I already looked the package documentation and searched for "drop" and "DROP" but didnt find anything :(

I drop table in case of SQL server and RODBC package by using sqlDrop command. I want it's equivalent for RMySQL package

user2543622
  • 5,760
  • 25
  • 91
  • 159
  • 1
    The `dbRemoveTable` should be what you are looking for. Alternatively, you could `dbGetQuery(conn,"DROP TABLE tablename")`. – nicola Oct 22 '14 at 19:18
  • put this as answer and i will accept it...thanks ...it answers my query – user2543622 Oct 22 '14 at 19:22
  • would you be able to answer http://stackoverflow.com/questions/26516501/r-dbbuildtabledefinition-mysql-rmysql-error-writing-a-table? – user2543622 Oct 22 '14 at 21:28

1 Answers1

5

Dropping tables in RMySQL is handled by the dbRemoveTable function. If you want to remove a table named test you can (assuming conn is your connection object):

dbRemoveTable(conn,"test")

Alternatively, you can use dbGetQuery to execute a command directly in MySQL (even if it doesn't return the result of a query). For instance:

dbGetQuery(conn,"DROP TABLE test")
nicola
  • 24,005
  • 3
  • 35
  • 56