Cum se utilizeaza bazele de date de tip Sqlite -1-

Buna ziua doamnelor si domnilor, bine v-am regasit. Ma numesc Zero Davila iar astazi vom invata despre cum sa lucram cu bazele de date de tip Sqlite. Sqlite e o baza de date light weight si portabila, in general utilizata de aplicatii mobile, dar folosita si pentru pagini web mici. In ultimul timp e din ce in ce mai folosita, avand in vedere ca mysql nu e chiar o necesitate absoluta in toate cazurile.

sqlite> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);

sqlite> CREATE TABLE DEPARTMENT(
ID INT PRIMARY KEY NOT NULL,
DEPT CHAR(50) NOT NULL,
EMP_ID INT NOT NULL
);

.tables

sqlite>.schema COMPANY
CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);

DROP TABLE database_name.table_name;

.tables

DROP TABLE COMPANY;

.tables

sqlite> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, ‘Paul’, 32, ‘California’, 20000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, ‘Allen’, 25, ‘Texas’, 15000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, ‘Teddy’, 23, ‘Norway’, 20000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, ‘Mark’, 25, ‘Rich-Mond ‘, 65000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, ‘David’, 27, ‘Texas’, 85000.00 );

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, ‘Kim’, 22, ‘South-Hall’, 45000.00 );

INSERT INTO COMPANY VALUES (7, ‘James’, 24, ‘Houston’, 10000.00 );
.header on

.mode column

SELECT * FROM COMPANY;

SELECT ID, NAME, SALARY FROM COMPANY;

.width 10, 20, 10

SELECT * FROM COMPANY;

SELECT sql FROM sqlite_master WHERE type = ‘table’ AND tbl_name = ‘COMPANY’;

SELECT (15 + 6) AS ADDITION;

SELECT COUNT(*) AS “RECORDS” FROM COMPANY;

SELECT CURRENT_TIMESTAMP;

SELECT * FROM COMPANY WHERE AGE >= 25 AND SALARY >= 65000;

SELECT * FROM COMPANY WHERE AGE >= 25 OR SALARY >= 65000;

SELECT * FROM COMPANY WHERE AGE IS NOT NULL;

SELECT * FROM COMPANY WHERE NAME LIKE ‘Ki%’;

SELECT * FROM COMPANY WHERE NAME GLOB ‘Ki*’;

SELECT * FROM COMPANY WHERE AGE IN ( 25, 27 );

SELECT * FROM COMPANY WHERE AGE NOT IN ( 25, 27 );

SELECT * FROM COMPANY WHERE AGE BETWEEN 25 AND 27;

SELECT AGE FROM COMPANY
WHERE EXISTS (SELECT AGE FROM COMPANY WHERE SALARY
> 65000);

SELECT * FROM COMPANY
WHERE AGE > (SELECT AGE FROM COMPANY WHERE SALARY
> 65000);

POST A COMMENT.