![]() SELECT * FROM contacts.people Code language: SQL (Structured Query Language) ( sql )įor more information on the ATTACH DATABASE statement, check out its documentation. Notice that we referred to the people table in the contacts database using the contacts.people naming convention.įinally, query data from the people table in the contacts database. people SELECT firstName, lastName FROM customers Code language: CSS ( css ) people( first_name text, last_name text) SQLite returns 2 databases as follows: seq name fileĢ contacts c:\sqlite\db\contacts.db Code language: SQL (Structured Query Language) ( sql )Īfter that, create a new table named people in the contacts database and populate data from the customers table in the main database. databases Code language: SQL (Structured Query Language) ( sql ) database command to display all databases in the current database connection. sqlite> attach database 'c:\sqlite\db\contacts.db' as contacts Code language: JavaScript ( javascript )įourth, use the. Then, use the ATTACH DATABASE statement to create a new database named contacts and associates it in the current database connection. seq name file -Ġ main c:\ sqlite\ db\ chinook. ![]() databases command to list all databases in the current database connection. SQLite ATTACH DATABASE exampleįirst, connect to the chinook sample database using sqlite3 command as follows: > sqlite3 c:\ sqlite\ db\ chinook. Note that SQLite automatically deletes all temporary and memory databases when the database connection is closed. If you specify an empty file name '', the statement creates a temporary file-backed database. You can attach multiple in-memory databases at the same time with a condition that each memory database must be unique. In case you want to create a new memory database and attach it to the current database connection, you use :memory: filename. For example, to refer to the people table in the contacts database, you use the contacts.people. Once the additional database attached, you can refer to all objects in the database under the name database_name. If the database file file_name does not exist, the statement creates a new database file. The statement associates the database file file_name with the current database connection under the logical database name database_name. To attach an additional database to the current database connection, you use the ATTACH DATABASE statement as follows: ATTACH DATABASE file_name AS database_name Code language: SQL (Structured Query Language) ( sql ) Therefore, every SQLite database connection has the main database and also temp database in case you deal with temporary database objects. In addition, you can access the temporary database that holds temporary tables and other database objects via the temp database. When you connect to a database, its name is main regardless of the database file name. Introduction to the SQLite ATTACH DATABASE statement ![]() Summary: in this tutorial, you will learn how to attach additional databases to the current database connection using the SQLite ATTACH DATABASE statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |