[英]SQL DROP TABLE FUNCTION
Hello i've created a table if in a VM provided by my university and inserted the following:您好,如果在我的大学提供的 VM 中,我已经创建了一个表并插入了以下内容:
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.但是,我实际上插入了我的名字,而不是 first_name 和 last_name,我希望删除该表以重新创建它。
" I typed in DROP TABLE [IF EXISTS] first_table
" “我输入了
DROP TABLE [IF EXISTS] first_table
”
and then it simply doesn't do anything.然后它根本不做任何事情。 Any idea why.
知道为什么。
In the Postgresql documentation, when you see something inside square brackets such as [IF EXISTS]
it means that "IF EXISTS" is optional.在 Postgresql 文档中,当您在方括号内看到诸如
[IF EXISTS]
这意味着“IF EXISTS”是可选的。 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:但是,在这种情况下,您知道该表存在,因此只需将“IF EXISTS”部分关闭即可:
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鉴于问题是您键入了您的名字和姓氏而不是所需的列名(
first_name
和last_name
),您可以简单地使用重命名列
alter table first_table
rename leo as first_name
alter table first_table
rename whatever_your_last_name_is as last_name
尝试这个:
DROP TABLE first_table;
在 PSQL 中,您应该能够使用命令DROP TABLE first_table;
这样做DROP TABLE first_table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.