leo
leo

Reputation: 1

SQL DROP TABLE FUNCTION

Hello i've created a table if in a VM provided by my university and inserted the following:

create table first_table (record_id int primary key,
first_name varchar(20) not null,
last_name varchar(20) not null);

However, instead of the first_name and last_name I actually inserted my name and am looking to drop the table to recreate it.

" I typed in DROP TABLE [IF EXISTS] first_table "

and then it simply doesn't do anything. Any idea why.

Upvotes: 0

Views: 241

Answers (3)

In the Postgresql documentation, when you see something inside square brackets such as [IF EXISTS] it means that "IF EXISTS" is optional. You shouldn't type the square brackets if you put that in.

In this case, though, you know that the table exists so just leave the "IF EXISTS" part off:

drop table first_table;

Given that the problem is that you typed your first and last names instead of the desired column name (first_name and last_name) you can simply rename the columns using

alter table first_table
  rename leo as first_name

alter table first_table
  rename whatever_your_last_name_is as last_name

Upvotes: 1

franklinturtle
franklinturtle

Reputation: 66

In PSQL you should be able to do so using the command DROP TABLE first_table;

Upvotes: 0

Toni
Toni

Reputation: 1585

Try this:

DROP TABLE first_table;

Upvotes: 0

Related Questions