Questions tagged [drop-table]

The SQL command for deleting an entire table.

DROP TABLE is used in SQL to remove a table.

140 questions
168
votes
5 answers

DROP IF EXISTS VS DROP?

Can someone tell me if there is any difference between DROP IF EXISTS [TABLE_NAME] DROP [TABLE_NAME] I am asking this because I am using JDBC template in my MVC web application. If I use DROP [TABLE_NAME] the error said that Table exist. And if I…
AbdulAziz
  • 4,948
  • 12
  • 51
  • 75
166
votes
14 answers

SQL DROP TABLE foreign key constraint

If I want to delete all the tables in my database like this, will it take care of the foreign key constraint? If not, how do I take care of that first? GO IF OBJECT_ID('dbo.[Course]','U') IS NOT NULL DROP TABLE dbo.[Course] GO IF…
user188229
115
votes
4 answers

Drop multiple tables in one shot in MySQL

How to drop multiple tables from one single database at one command. something like, > use test; > drop table a,b,c; where a,b,c are the tables from database test.
Krunal
  • 1,691
  • 3
  • 11
  • 12
70
votes
6 answers

Can't drop table: A foreign key constraint fails

In MySQL I want to drop a table. I tried a lot things but I keep getting the error that the table named bericht can't be dropped. This is the error I'm getting: #1217 - Cannot delete or update a parent row: a foreign key constraint fails How do I…
roy
  • 711
  • 1
  • 5
  • 4
60
votes
5 answers

How to delete a table in SQLAlchemy?

I want to delete a table using SQLAlchemy. Since I am testing over and over again, I want to delete the table my_users so that I can start from scratch every single time. So far I am using SQLAlchemy to execute raw SQL through the engine.execute()…
fedorqui 'SO stop harming'
  • 228,878
  • 81
  • 465
  • 523
30
votes
5 answers

Android SQLite Database, WHY drop table and recreate on upgrade

In the tutorials I am following and a lot of more places I see this, onUpgrade -> drop table if exists, then recreate table. What is the purpose of this? private static class DbHelper extends SQLiteOpenHelper{ public DbHelper(Context context)…
Esqarrouth
  • 35,175
  • 17
  • 147
  • 154
26
votes
3 answers

SQL Server: Does 'DROP TABLE' inside transaction causes an implicit commit?

My question is kind of easy but i'm still doubting after I created this transaction. If I execute the following code: BEGIN TRANSACTION DROP TABLE Table_Name Can I perform a ROLLBACK TRANSACTION that recovers the dropped table? I'm asking…
Mauro Bilotti
  • 3,823
  • 2
  • 30
  • 55
21
votes
10 answers

How to drop all tables in database without dropping the database itself?

I would like to delete all the tables from database, but not deleting the database itself. Is it possible ? I'm just looking for shorter way than removing the database and create it again. Thanks !
Misha Moroshko
  • 148,413
  • 200
  • 467
  • 700
19
votes
6 answers

error in sqlite "DROP TABLE IF EXISTS" android

so i have a problem in my DBAdapter class its just crushes when i try to open the database: from the LogCat i guess the problem is in the onUpgrade function: public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { …
eli
  • 481
  • 1
  • 3
  • 21
15
votes
6 answers

Dropping a table in SAS

What is the most efficient way to drop a table in SAS? I have a program that loops and drops a large number of tables, and would like to know if there is a performance difference between PROC SQL; and PROC DATASETS; for dropping a single table at a…
Allan Bowe
  • 11,461
  • 18
  • 65
  • 114
15
votes
2 answers

Drop all tables sql developer

I have tables that names start with "TBL_*", but I can not drop all of them by single command. how can I drop this tables?
Emad Aghayi
  • 621
  • 1
  • 7
  • 21
13
votes
6 answers

hive - how to drop external hive table along with data

I am using drop table If I recreate the table with the same schema and name, I am getting the old data back. Should I remove the table directory from hdfs file system to completely get rid of the data?
amrk7
  • 1,144
  • 4
  • 13
  • 29
12
votes
2 answers

How to drop a single Postgres table in a Ruby on Rails Heroku app?

Similar question here, but none of the answers actually answer the question. The accepted answer just shows how to log in to console and destroy all records. This is not what I need in this case. I need to completely scrap a single table (it has no…
sergserg
  • 19,010
  • 36
  • 118
  • 175
11
votes
2 answers

Drop temporary table when exiting a function

I use a temp table in a function with the 'on commit drop' option. My problem is, in certain cases, a more global function can call the first one twice, so the "create temp table" is called twice before the commit - so I have the normal error…
Thomas Perrin
  • 393
  • 1
  • 4
  • 15
10
votes
0 answers

aiopg + sqlalchemy: how to "drop table if exists" without raw sql?

I am looking at examples of aiopg usage with sqlalchemy and these lines scare me: async def create_table(conn): await conn.execute('DROP TABLE IF EXISTS tbl') await conn.execute(CreateTable(tbl)) I do not want to execute raw sql queries…
sanyassh
  • 6,892
  • 12
  • 21
  • 48
1
2 3
9 10