Cosc 5/4730 Sqlite primer.

Slides:



Advertisements
Similar presentations
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Advertisements

Structured Query Language Part I Chapter Three CIS 218.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Cosc 5/4730 Android and Blackberry SQLite. For the sql language syntax, please see SQlite documentation –
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
ASP.NET Programming with C# and SQL Server First Edition
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Introduction to Database Programming with Python Gary Stewart
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
Making content providers
SQL, the Structured Query Language
Data Storage: Part 3 (SQLite)
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Database Access with SQL
Chapter 5 Introduction to SQL.
MySQL DML Commands By Prof. B.A.Khivsara
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Insert, Update and the rest…
SQL – CRUD.
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
Introduction to Structured Query Language(SQL)
SQL Creating and Managing Tables
Mobile Computing With Android ACST Android Database Storage Part 2
SQL Creating and Managing Tables
Chapter 8 Working with Databases and MySQL
SQL Creating and Managing Tables
CIS 136 Building Mobile Apps
Introduction To Structured Query Language (SQL)
CREATE, INSERT, SELECT.
Access: SQL Participation Project
Introduction To Structured Query Language (SQL)
Android Developer Fundamentals V2
Structured Query Language Path from Unorganized to Organized….
Department of School of Computing and Engineering
SQLLite and Android.
Presentation transcript:

Cosc 5/4730 Sqlite primer

Table Creation Syntax CREATE TABLE database_name.table_name( column1 datatype PRIMARY KEY, column2 datatype, column3 datatype, ..... columnN datatype, );

Table Creation Example CREATE TABLE COMPANY( ID INT PRIMARY KEY AUTO INCREMENT, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS TEXT, SALARY REAL ); This the db fills in for you. NOT null means you have to Enter a value While these can be left blank

Data Types Type Description NULL The value is a NULL value. INTEGER The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. REAL The value is a floating point value, stored as an 8-byte IEEE floating point number. TEXT The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE) BLOB The value is a blob of data, stored exactly as it was input.

Delete table Syntax: Example DROP TABLE table_name; Example DROP TABLE company; A note, keywords don’t have to capitalized, it just to show them.

Insert Syntax: Example: INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN); Example: INSERT INTO COMPANY (NAME,AGE,ADDRESS, SALARY) VALUES ('Paul', 32, 'California', 20000.00 );

Insert android Long insert(String TABLE_NAME, String nullColumanHAack, ContentValues values); Where ContentValues is hash with column as a key and the value is the data. Likely nullColumnHack will be null.

Select (query) Basic version which will return all rows. SELECT column1, column2....columnN FROM table_name; //only return columns listed. SELECT * FROM table_name; //all columns So SELECT * FROM company; Will list all the rows in the company table. A note, you can lists the tables in the database with SELECT tbl_name FROM sqlite_master WHERE type = 'table';

Select (query) 2 Where cause. SELECT * FROM table_Name WHERE [condition]; SELECT * FROM company WHERE age >=25; Operators ==, = (same as ==), !=, <> ( same as !=), <, >, >=, <=, !>, !< Operators +, -, *, / % (modulus) can be used as well Logical operator can be used as well. SELECT * FROM company WHERE age >=25 AND salary <= 50000; SELECT * FROM COMPANY WHERE NAME LIKE ‘Ji%'; SELECT * FROM COMPANY WHERE AGE IS NOT NULL;

Logical operators Operator Description AND The AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause. BETWEEN The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value. EXISTS The EXISTS operator is used to search for the presence of a row in a specified table that meets certain criteria. IN The IN operator is used to compare a value to a list of literal values that have been specified. NOT IN The negation of IN operator which is used to compare a value to a list of literal values that have been specified. LIKE The LIKE operator is used to compare a value to similar values using wildcard operators. GLOB The GLOB operator is used to compare a value to similar values using wildcard operators. Also, GLOB is case sensitive, unlike LIKE. NOT The NOT operator reverses the meaning of the logical operator with which it is used. Eg. NOT EXISTS, NOT BETWEEN, NOT IN, etc. This is negate operator. OR The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause. IS NULL The NULL operator is used to compare a value with a NULL value. IS The IS operator work like = IS NOT The IS operator work like != || Adds two different strings and make new one. UNIQUE The UNIQUE operator searches every row of a specified table for uniqueness (no duplicates).

Query android Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) GroupBy, having, and OrderBy are shown later in the slides When in doubt on a query, use Cursor rawQuery (String sql, String[] selectionArgs) With selectionArgs as null.

UPDATE Syntax UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition]; Example UPDATE COMPANY SET addres = 'Texas' WHERE id = 6; A Note, if you leave off the where cause, it will update every row.

UPDATE Android int update(String table, ContentValues values, String whereClause, String[] whereArgs)

Delete Syntax DELETE FROM table_name WHERE [condition]; Example DELETE FROM company WHERE id = 7; A Note, if you leave off the where cause, it will delete every row.

Delete Android int delete(String table, String whereClause, String[] whereArgs)

Limit cause The SQLite LIMIT clause is used to limit the data amount returned by the SELECT statement. Syntax SELECT column1, column2, columnN FROM table_name LIMIT [no of rows] SELECT column1, column2, columnN FROM table_name LIMIT [no of rows] OFFSET [row num] Examples SELECT * FROM COMPANY LIMIT 6; //only 6 rows SELECT * FROM COMPANY LIMIT 3 OFFSET 2; //start at row 3 and return 3 rows. (ie row 3 to 5)

ORDER BY cause Syntax: example SELECT * … [ ORDER BY column1, column2, …] [ASC | DESC] Where ASC is ascending, DESC is descending default is ascending example SELECT * FROM company ORDER BY salary; SELECT * FROM COMPANY ORDER BY name, salary DESC; Descending order by name and then by salary

GROUP BY cause clause is used in collaboration with the SELECT statement to arrange identical data into groups. Note the ORDER BY must follow the GROUP BY Syntax: SELECT column-list FROM table_name WHERE [ conditions ] GROUP BY column1, column2....columnN ORDER BY column1, column2....columnN

execSQL execSQL(String sql, Object[] bindArgs) Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.

Reference http://www.tutorialspoint.com/sqlite/sqlite_syntax.htm And lot more information then provided here. http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html