SQL Script
- Get link
- X
- Other Apps
1
2
3
4
5
6
7
create table customers ( id INTEGER, name text, age INTEGER
);
insert into customers values ( 1, "sital", 2);
SELECT * FROM customers;
SQL development
If you're new to SQL, you can learn more from this course: SQL.
Creating tables
- Many data typesCREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, weight REAL);
- Using primary keysCREATE TABLE customers (id INTEGER PRIMARY KEY, age INTEGER);
See also: specifying defaults, using foreign keys. For more details, see the following: SQLite reference for CREATE.
Inserting data
- Inserting dataINSERT INTO customers VALUES (73, "Brian", 33);
- Inserting data for named columnsINSERT INTO customers (name, age) VALUES ("Brian", 33);
See also: The SQLite reference for INSERT.
Querying data
- Select everythingSELECT * FROM customers;
- Filter with conditionSELECT * FROM customers WHERE age > 21;
- Filter with multiple conditionsSELECT * FROM customers WHERE age < 21 AND state = "NY";
- Filter with INSELECT * FROM customers WHERE plan IN ("free", "basic");
- Select specific columnsSELECT name, age FROM customers;
- Order resultsSELECT * FROM customers WHERE age > 21 ORDER BY age DESC;
- Transform with CASESELECT name, CASE WHEN age > 18 THEN "adult" ELSE "minor" END "type" FROM customers;
See also: filtering with LIKE, restricting with LIMIT, using ROUND and other core functions. For more details, see: the SQLite reference for SELECT.
Aggregating data
- Aggregate functionsSELECT MAX(age) FROM customers;
- Grouping dataSELECT gender, COUNT(*) FROM students GROUP BY gender;
See also: restricting results with HAVING.
Joining related tables
- Inner joinSELECT customers.name, orders.item FROM customers JOIN orders ON customers.id = orders.customer_id;
- Outer joinSELECT customers.name, orders.item FROM customers LEFT OUTER JOIN orders ON customers.id = orders.customer_id;
Updating and deleting data
- Updating dataUPDATE customers SET age = 33 WHERE id = 73;
- Deleting dataDELETE FROM customers WHERE id = 73;
- Get link
- X
- Other Apps

Comments
Post a Comment