PostgreSQL:在特定数据库中创建模式 [英] PostgreSQL: Create schema in specific database
问题描述
我需要编写一个 sql脚本,它可以在我刚创建的数据库中创建新数据库和新模式 p>
我该怎么办?我可以以某种方式将当前数据库更改为新的?或者我可以以某种方式指定CREATE SCHEMA的数据库吗?
我使用PostgreSQL 9.0
您可以连接到数据库,并执行CREATE SCHEMA语句。这将导致该数据库中的新模式。它不像你想象的那么强大);当你想要从.SQL文件做这个,你可以这样使用\connect命令:
CREATE DATABASE foo;
\connect foo;
CREATE SCHEMA yourschema;
I need to write an sql script that creates both a new database AND a new schema in the database I just created.
How can I do it? Can I somehow change the current database to the new one? Or can I somehow specify the database for CREATE SCHEMA?
I'm using PostgreSQL 9.0
You can connect to the database, and execute the "CREATE SCHEMA" statement. That should result in a new schema in that database. It's not as tough as you think ;) When you want to do this from a .SQL file instead, you can use the \connect command as such:
CREATE DATABASE foo;
\connect foo;
CREATE SCHEMA yourschema;
这篇关于PostgreSQL:在特定数据库中创建模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!