List all tables in a DB using SQLite - sqlite

I can't seem to find documentation (that I understand) on how to list all tables in a database. I've tried the following:
SELECT * FROM .table;
SELECT * FROM .tab;
SELECT * FROM .db;
SELECT * FROM world.db;
None of them worked. I'm just learning SQL, so forgive my ignorance. :0)

Try this:
SELECT * FROM sqlite_master WHERE type='table'

If you are in interactive mode, you can use this:
.tables
Another method with extra information:
.schema
https://sqlite.org/cli.html#querying_the_database_schema

Related

OpenQuery for SQL Query

Kindly help me writing below query in openquery.Thanks in advance
INSERT INTO Tablename
SELECT * FROM tablename1 WHERE insertionorderid IN (
SELECT orderid FROM temp_table2)
If you are trying to insert into SQL Server the syntax would be
INSERT INTO dbo.[YOURTABLE] SELECT * FROM [MATCHING_TABLE] WHERE CLAUSE
The caveat here is that the two tables must have identical schemas or you will have to explicitly define the columns. Also this will not work properly for tables with identity columns

SQLite accent-insensitive search

Is there any way to do an accent-insensitive LIKE query in SQLite? For example, this query:
SELECT * FROM users WHERE name LIKE "Andre%"
would return:
André the Giant
Andre Agassi
etc.
I'm using Qt with QSqlDatabase if it makes any difference.
Set up a collation using sqlite3_create_collation and then use it like this:
SELECT * FROM users WHERE name LIKE "Andre%" COLLATE NOACCENTS

Oracle - Getting the fields of all tables in a database

I know that to find all the fields of a table I should use something like
sqlplus > desc testtable;
This lists all the fields of a table (here testtable)
But now, I have a list of tables in my database.
What is the way through which I can get the fields of all tables
in a given database using sqlplus?
I tried
sqlplus > desc <Databasename>; which didnot work.
Someone told me to use
sqlplus > select * from INFORMATION_SCHEMA.TABLES ; //gives error.
SQLPLUS > SELECT * FROM INFORMATION_SCHEMA.COLUMNS; //gives some error.
(At the bottom line, I am trying to get the database schema.)
I don't believe that the information_schema tables you can find in other dbs (SQL Server, PostGres, MySQL, etc) is in Oracle. I use to use the ALL_TAB_COLUMNS table to get at that type of information....maybe another alternative.
Link: ALL_TAB_COLUMNS

Show only VIEWS in SQLite

How can i see only VIEWS in SQLite.
.tables command list both views as well as tables. I want to see only VIEWS and not tables.
Thanks.
You can do:
SELECT sql FROM sqlite_master WHERE type = 'view';
In order to fine-tune it:
.headers on
select * from sqlite_master;
you will know what columns are available there.

SELECT INTO statement in sqlite

Does sqlite support the SELECT INTO statement?
Actually I am trying to save the data in table1 into table2 as a backup of my database before modifying the data.
When I try using the SELECT INTO statement:
SELECT * INTO equipments_backup FROM equipments;
I get a syntax error:
"Last Error Message:near "INTO":syntax
error".
Instead of
SELECT * INTO equipments_backup FROM equipments
try
CREATE TABLE equipments_backup AS SELECT * FROM equipments
sqlite does not support SELECT INTO.
You can probably use this form instead:
INSERT INTO equipments_backup SELECT * FROM equipments;
SQlite didn't have INSERT INTO syntax.
In 2019, I use TEMPORARY keyword to create temporary table and INSERT data to temp table:
CREATE TEMPORARY TABLE equipments_backup(field1 TEXT, field2 REAL)
INSERT INTO equipments_backup SELECT field1, field2 FROM equipments

Resources