0% found this document useful (0 votes)
26 views

Criando Tabelas

SQL is a language used to create, manipulate, and retrieve data stored in relational databases. The document provides examples of SQL commands to create a table, insert data, select data with conditions and ordering, aggregate data, join related tables, and update and delete data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Criando Tabelas

SQL is a language used to create, manipulate, and retrieve data stored in relational databases. The document provides examples of SQL commands to create a table, insert data, select data with conditions and ordering, aggregate data, join related tables, and update and delete data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL

Criando tabelas

CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, age
INTEGER, weight REAL);

Insero de dados

INSERT INTO customers VALUES (73, "Brian", 33);

Consultando dados

SELECT * FROM customers; (selecionando tudo)


SELECT * FROM customers WHERE age < 21 AND state = "NY";
(selecionando com condies)
SELECT name, age FROM customers; (selecionando colunas especficas)
SELECT name, CASE WHEN age > 18 THEN "adult" ELSE "minor" END "type"
FROM customers; (transformar com CASE)
SELECT * FROM customers WHERE age > 21 ORDER BY age DESC; (ordenar
resultados)

Agregando dados

SELECT MAX(age) FROM customers;


SELECT gender, COUNT(*) FROM students GROUP BY gender; (arupamento
de dados)

Associando tabelas relacionadas

SELECT customers.name, orders.item FROM customers JOIN orders ON


customers.id = orders.customer_id;

Atualizao e excluso de dados

UPDATE customers SET age = 33 WHERE id = 73;

You might also like