GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — SQLite - ATTACH Database

SQLite Tutorial
  • SQLite - Home
  • SQLite - Overview
  • SQLite - Installation
  • SQLite - Commands
  • SQLite - Syntax
  • SQLite - Data Type
  • SQLite - CREATE Database
  • SQLite - ATTACH Database
  • SQLite - DETACH Database
  • SQLite - CREATE Table
  • SQLite - DROP Table
  • SQLite - INSERT Query
  • SQLite - SELECT Query
  • SQLite - Operators
  • SQLite - Expressions
  • SQLite - WHERE Clause
  • SQLite - AND & OR Clauses
  • SQLite - UPDATE Query
  • SQLite - DELETE Query
  • SQLite - LIKE Clause
  • SQLite - GLOB Clause
  • SQLite - LIMIT Clause
  • SQLite - ORDER By Clause
  • SQLite - GROUP By Clause
  • SQLite - HAVING Clause
  • SQLite - DISTINCT Keyword

SQLite Advanced Concepts

  • SQLite - PRAGMA
  • SQLite - Constraints
  • SQLite - JOINS
  • SQLite - UNION Clause
  • SQLite - NULL Values
  • SQLite - ALIAS Syntax
  • SQLite - Triggers
  • SQLite - Indexes
  • SQLite - INDEXED By Clause
  • SQLite - ALTER Command
  • SQLite - TRUNCATE Command
  • SQLite - Views
  • SQLite - Transactions
  • SQLite - Subqueries
  • SQLite - AUTOINCREMENT
  • SQLite - Injection
  • SQLite - EXPLAIN
  • SQLite - VACUUM
  • SQLite - Date & Time
  • SQLite - Useful Functions

SQLite Interfaces

  • SQLite - C/C++
  • SQLite - Java
  • SQLite - PHP
  • SQLite - Perl
  • SQLite - Python

SQLite Useful Resources

  • SQLite - Quick Guide
  • SQLite - Useful Resources
  • SQLite - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

SQLite - ATTACH Database



Previous
Quiz
Next

Consider a case when you have multiple databases available and you want to use any one of them at a time. SQLite ATTACH DATABASE statement is used to select a particular database, and after this command, all SQLite statements will be executed under the attached database.

Syntax

Following is the basic syntax of SQLite ATTACH DATABASE statement.

ATTACH DATABASE 'DatabaseName' As 'Alias-Name';

The above command will also create a database in case the database is already not created, otherwise it will just attach database file name with logical database 'Alias-Name'.

Example

If you want to attach an existing database testDB.db, then ATTACH DATABASE statement would be as follows −

sqlite> ATTACH DATABASE 'testDB.db' as 'TEST';

Use SQLite .database command to display attached database.

sqlite> .database
seq  name             file
---  ---------------  ----------------------
0    main             /home/sqlite/testDB.db
2    test             /home/sqlite/testDB.db

The database names main and temp are reserved for the primary database and database to hold temporary tables and other temporary data objects. Both of these database names exist for every database connection and should not be used for attachment, otherwise you will get the following warning message.

sqlite> ATTACH DATABASE 'testDB.db' as 'TEMP';
Error: database TEMP is already in use
sqlite> ATTACH DATABASE 'testDB.db' as 'main';
Error: database TEMP is already in use
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.