SQLite on Mac OS X examples

Here I decided to write some SQLite(SQLite on wiki) on Mac OS X examples of code for creation of database and database management.

1. Go to the folder where you want to create SQLite database (all this is written on Applications/Services/Terminal):

cd /Users/user/Documents/

2. Create database:

sqlite3 SimpleVocabulary.sql

3. Create table in that database:

CREATE TABLE Cards(CardID VARCHAR(5) PRIMARY KEY, Word VARCHAR(1000), Translation VARCHAR(3000), MemoStatus VARCHAR(1));

4. Insert values to the table:

INSERT INTO Cards VALUES ("1", "Mother", "Mama", "Y");

5. Select values from table:

SELECT * FROM Cards;

Another code examples:

1. cd /Users/user/Documents/
2. sqlite3 TexDatabase.sql
1.SELECT * FROM Lessons;
2.SELECT COUNT(*) FROM Lessons;
3.DELETE FROM Lessons;
4.CREATE TABLE Lessons(LessonID VARCHAR(5) PRIMARY KEY, LessonGroup VARCHAR(5), LessonTopic VARCHAR(100), LessonText VARCHAR(20000), LessonCode VARCHAR(100), LessonPicture VARCHAR(100));
5.Drop table Lessons;
6..schema

Here .schema command allows you to look at your tables structure.

Another example:
1. cd /Users/user/Desktop/Alwawee/AlwaweeApps/Бизнес-цитаты/Database
2. sqlite3 BusCitDatabase.sql
3. sqlite> CREATE TABLE BusCits(ID VARCHAR(5) PRIMARY KEY, Text VARCHAR(3000), Author VARCHAR(500));
4. sqlite> .quit
5. SELECT COUNT(*) FROM BusCits;
6. SELECT COUNT(*) FROM BusAuthors;
7. sqlite> CREATE TABLE BusAuthors(AuthorID VARCHAR(5) PRIMARY KEY, AuthorName VARCHAR(100), AuthorInfo VARCHAR(3000));
8. SELECT COUNT(*) FROM BusAuthors;
9. DELETE FROM BusAuthors;
10. DELETE FROM BusCits;
11. SELECT DISTINCT Author FROM BusCits WHERE Author NOT IN(SELECT AuthorName FROM BusAuthors);
12. cd /Users/user/Documents/
13. cd SimpVoc
14. sqlite3 TransWords.sql
15. INSERT INTO Cards VALUES ("1", "Mother", "Madre", "Y");
16. INSERT INTO Cards VALUES ("2", "Example", "Ejemplo", "Y");
17. INSERT INTO Cards VALUES ("3", "World", "Mundo", "Y");
18. SELECT * FROM Cards;

Here .quit command quits sqlite> mode on your Terminal.

Leave a Reply

Your email address will not be published. Required fields are marked *