Questions tagged [drop-table]

The SQL command for deleting an entire table.

DROP TABLE is used in SQL to remove a table.

152 questions
0
votes
2 answers

Mysql drop table/create table sequence gives strange error

This situation makes no sense. I have the following sequence of SQL operations in my php code: DROP TABLE IF EXISTS tablename; CREATE TABLE tablename; Of course the php code does not look like that, but those are the commands being…
Jeffrey Simon
  • 918
  • 3
  • 11
  • 25
0
votes
0 answers

How to avoid errors on tables that are dropped to begin a SQL query?

At the top of my query I have a few statements that drop tables if they exist, such as: IF OBJECT_ID('dbo.vanguardsummary', 'U') IS NOT NULL DROP TABLE dbo.vanguardsummary; Later on I drop a particular column from one of the newly dropped and…
0
votes
2 answers

My Bigquery SQL wont use functions such as YEAR or CREATE or DROP

I am new to Big Query and I am trying to understand why my script doesn't work. Script is below DROP TEMP TABLE top1; CREATE TEMP TABLE topl (Language STRING, NoofRepos INTEGER); INSERT INTO topl (SELECT l.language.name Language, COUNT(*) AS…
0
votes
1 answer

oracle drop table if exists pl/sql not working using exception

oracle: drop table if exists pl/sql not working using exception. e.g., SQL> SET SERVEROUTPUT ON SQL> BEGIN SQL> EXECUTE IMMEDIATE 'DROP TABLE Foo'; SQL> EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(sqlerrm); SQL> END; SQL> / The Foo table…
eastwater
  • 4,624
  • 9
  • 49
  • 118
0
votes
1 answer

Postgres DROP TABLE using DO DECLARE and EXECUTE

I'm trying to drop tables returned from a query using EXECUTE. Here's an example: CREATE TABLE test_a (id BIGINT); CREATE TABLE test_b (id BIGINT); DO $f$ DECLARE command TEXT; BEGIN SELECT INTO command 'SELECT ARRAY_TO_STRING(ARRAY_AGG($$DROP…
douglas_forsell
  • 111
  • 1
  • 10
0
votes
0 answers

SQL : move a column from one table to the other

I have SQL code that adds a new column with a default value for each row in a table in my database. I need it to also remove that same column from another table at the same time, and I'm not sure about the syntax. create procedure…
Zusman
  • 606
  • 1
  • 7
  • 31
0
votes
2 answers

Drop table only if it exists, or ignore drop error

I have a table MYLOG and would like to try drop it before creating it using the SQL script below. If the table does not exist yet, the error below is throw. How could I bypass this error if the table does not exist? The schema gets set in an earlier…
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150
0
votes
1 answer

Temp table not dropping when run in batch with inser

So the below doesn't work when run. I added the column [Target_Id] INT to my Create Table statement. It now throws the error: Msg 213, Level 16, State 1, Line 1376 Column name or number of supplied values does not match table…
Jamie Marshall
  • 1,885
  • 3
  • 27
  • 50
0
votes
1 answer

PDO - can both CREATE and DROP statements be in the same query?

I have SQL code that executes CREATE TABLE and DROP TABLE in the same query. When I run it, it prints bool(false) meaning error. Can it be done in one query? $dbh = new PDO("sqlite::memory:"); $stmt = $dbh->prepare("create table a ( i int, j…
jiwopene
  • 3,077
  • 17
  • 30
0
votes
1 answer

How to recover a dropped table in sql server after a full backup taken

I have to recover a dropped table from a SQL Server database which runs on SQL Server 2016 Standard edition. Database is in full recovery mode. After the dropped the table, I took a full database backup and then transaction log backup twice. Now…
Ivan Lewis
  • 740
  • 1
  • 9
  • 19
0
votes
0 answers

Dropped postgres tables recreated when database dropped and recreated

I'm trying to programatically create and drop databases for testing purposes in Postgres. I can't for the life of me get it to actually make the tables go away when I run DROP TABLE commands, though, and it's causing my script to fail (via…
adavea
  • 1,535
  • 1
  • 19
  • 25
0
votes
1 answer

DROP table using Room persistence library

Is there any way to drop tables directly while using Room . I have tried the below code under DAO class @Query( "DROP TABLE IF EXISTS 'tablename'" ) void dropFavoriteShowEpisodeTable(); But I am unable to build and error is UNKNOWN query type…
XylemRaj
  • 772
  • 4
  • 13
  • 28
0
votes
1 answer

SQL Server 2017 - Database mail stored procedure

I have a stored procedure which basically I want to do the following: Create temp table (if not exists) and populate with data Output the query to SSMS, and assigning the query a variable (@sql) Using the query, e-mail the contents of the query to…
0
votes
1 answer

MySQL Drop Table Inside Trgigger

CREATE TRIGGER trg_alis AFTER INSERT ON alis_acik_emirler FOR EACH ROW BEGIN DROP TABLE alis2; CREATE TABLE alis2 ( emirID int NOT NULL AUTO_INCREMENT, userID int, fiyat int, adet int, …
Canydor
  • 1
  • 3
0
votes
2 answers

Why drop table cascade is not removing child table in postgresql?

I have following two tables, whose schema looks like given below :- postgres=# \d products1; Table "public.products1" Column | Type | …
Mangu Singh Rajpurohit
  • 10,806
  • 4
  • 68
  • 97