SQLite Forum

USE statement, or a way to set default schema
Login

USE statement, or a way to set default schema

(1) By anonymous on 2022-01-17 11:34:28 [link] [source]

Hi guys,

Just wondering if there is a way to set the dafault schema to something other than 'main'?

Seems like a useful feature when working with more than one schema, where one wants to set one schema to be used for a set of following CREATE statements.

(2) By Simon Slavin (slavin) on 2022-01-17 13:52:30 in reply to 1 [source]

I'm not up on how SQLite works internally, but it seems likely that having to have every SQL statement look up which schema it should use for the default would slow down SQLite.

You should be able to create an empty database and open that as your 'main' database. Then you open 'real' databases using the ATTACH command, which allows you to set whatever schema names (within reason) you want for each one.

That way you'll never use the main database, which means the default schema has no meaning.