SQLITE: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
|||
Linha 80: | Linha 80: | ||
PRAGMA table_info(table_name); | PRAGMA table_info(table_name); | ||
</syntaxhighlight > | </syntaxhighlight > | ||
== SQLite: Comandos Básicos == | |||
'''SQLite''' é um sistema de gerenciamento de banco de dados relacional leve e autônomo. Abaixo estão alguns dos comandos SQL mais comuns usados no SQLite. | |||
=== Criar Tabela === | |||
Para criar uma nova tabela: | |||
<syntaxhighlight lang="sql"> | |||
CREATE TABLE usuarios ( | |||
id INTEGER PRIMARY KEY, | |||
nome TEXT NOT NULL, | |||
email TEXT UNIQUE | |||
); | |||
</syntaxhighlight> | |||
=== Inserir Dados === | |||
Para inserir dados em uma tabela: | |||
<syntaxhighlight lang="sql"> | |||
INSERT INTO usuarios (nome, email) VALUES ('Maria', 'maria@exemplo.com'); | |||
</syntaxhighlight> | |||
=== Consultar Dados === | |||
Para consultar todos os registros: | |||
<syntaxhighlight lang="sql"> | |||
SELECT * FROM usuarios; | |||
</syntaxhighlight> | |||
Com condição: | |||
<syntaxhighlight lang="sql"> | |||
SELECT nome FROM usuarios WHERE id = 1; | |||
</syntaxhighlight> | |||
=== Atualizar Dados === | |||
Para atualizar um registro: | |||
<syntaxhighlight lang="sql"> | |||
UPDATE usuarios SET email = 'novo@exemplo.com' WHERE id = 1; | |||
</syntaxhighlight> | |||
=== Excluir Dados === | |||
Para excluir um registro: | |||
<syntaxhighlight lang="sql"> | |||
DELETE FROM usuarios WHERE id = 1; | |||
</syntaxhighlight> | |||
=== Deletar Tabela === | |||
Para remover completamente uma tabela: | |||
<syntaxhighlight lang="sql"> | |||
DROP TABLE usuarios; | |||
</syntaxhighlight> | |||
=== Ver Todas as Tabelas === | |||
Para listar todas as tabelas do banco de dados: | |||
<syntaxhighlight lang="sql"> | |||
SELECT name FROM sqlite_master WHERE type='table'; | |||
</syntaxhighlight> | |||
== Referências == | |||
* [https://www.sqlite.org/lang.html Documentação oficial do SQLite] |
Edição atual tal como às 19h15min de 26 de maio de 2025
Links
SQLite
Command line
$ sqlite3 base.db -csv "select * from table" | tee output.csv
$ sqlite3 base.db -headers "select * from table" | column -t -s \|
Create BASE
CREATE TABLE IF NOT EXISTS arquitetura(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
HOSTNAME text,
PUBLIC_IP text,
STATE text,
LOCAL_ADDRESS text,
LOCAL_PORT integer,
REMOTE_ADDRESS text,
REMOTE_PORT integer,
PROCESS_ID integer,
PROCESS_NAME text,
OS_VERSION text,
PROCESSOR_COUNT integer,
RAM_MEMORY_KB real)
Select
Example
SELECT DISTINCT
HOSTNAME,
REMOTE_ADDRESS,
REMOTE_PORT,
PROCESS_NAME
FROM
arquitetura
WHERE
STATE == 'ESTABLISHED'
AND
LOCAL_PORT NOT IN (
SELECT DISTINCT
LOCAL_PORT
FROM
arquitetura
WHERE
STATE == 'LISTENING'
AND
LOCAL_ADDRESS <> '127.0.0.1'
)
AND
LOCAL_ADDRESS <> '127.0.0.1'
ORDER BY
'REMOTE_PORT'
Delete
Example
delete from bloqueios where timestamp <= '$(expr $(date +"%s") - 10368000)'
List Tables
.tables
SELECT
name
FROM
sqlite_schema
WHERE
type ='table' AND
name NOT LIKE 'sqlite_%';
Get Table Info
PRAGMA table_info(table_name);
SQLite: Comandos Básicos
SQLite é um sistema de gerenciamento de banco de dados relacional leve e autônomo. Abaixo estão alguns dos comandos SQL mais comuns usados no SQLite.
Criar Tabela
Para criar uma nova tabela:
CREATE TABLE usuarios (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
email TEXT UNIQUE
);
Inserir Dados
Para inserir dados em uma tabela:
INSERT INTO usuarios (nome, email) VALUES ('Maria', 'maria@exemplo.com');
Consultar Dados
Para consultar todos os registros:
SELECT * FROM usuarios;
Com condição:
SELECT nome FROM usuarios WHERE id = 1;
Atualizar Dados
Para atualizar um registro:
UPDATE usuarios SET email = 'novo@exemplo.com' WHERE id = 1;
Excluir Dados
Para excluir um registro:
DELETE FROM usuarios WHERE id = 1;
Deletar Tabela
Para remover completamente uma tabela:
DROP TABLE usuarios;
Ver Todas as Tabelas
Para listar todas as tabelas do banco de dados:
SELECT name FROM sqlite_master WHERE type='table';