SQL – CRUD.

Slides:



Advertisements
Similar presentations
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Advertisements

Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
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.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Databases.  Question 1: What does SQL stand for? …………………………………………………………………… (1 point)  Question 2: Considering programming paradigms, what kind of language.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
Relational Database Design and MySQL Charles Severance
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
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.
Fundamentals of DBMS Notes-1.
Database Access with SQL
Cosc 5/4730 Sqlite primer.
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Stored Procedures.
Tables and Triggers.
The Basics of Data Manipulation
Database structure and space Management
Insert, Update and the rest…
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
 2012 Pearson Education, Inc. All rights reserved.
Indices.
SQL – More Table Constraints
Session 4 PHP & MySQL.
ITEC 313 Database Programming
CS1222 Using Relational Databases and SQL
Lecturer: Mukhtar Mohamed Ali “Hakaale”
CS1222 Using Relational Databases and SQL
Chapter 5 Sequences.
The Basics of Data Manipulation
What is a Database? A collection of data organized in a manner that allows access, retrieval, and use of that data.
“Manipulating Data” Lecture 6.
Structured Query Language
Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.
Developing a Model-View-Controller Component for Joomla Part 3
Access: SQL Participation Project
CS122 Using Relational Databases and SQL
“Manipulating Data” Lecture 6.
CS122 Using Relational Databases and SQL
Data Management Innovations 2017 High level overview of DB
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Introduction To Structured Query Language (SQL)
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Data Definition Language
Data Definition Language
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Manipulating Data Lesson 3.
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
SQL AUTO INCREMENT Field
Presentation transcript:

SQL – CRUD

CRUD Four fundamental operations that apply to any database are: Read the data  --  SELECT Insert new data  --  INSERT Update existing data  --  UPDATE Remove data  --  DELETE Collectively these are referred to as CRUD (Create, Read, Update, Delete). https://www.facebook.com/cruddetroit/photos/a.205752358996.130316.180071488996/10153406728943997/?type=3

INSERT INTO The INSERT INTO statement is used to add new data to a database. The INSERT INTO statement adds a new record to a table. INSERT INTO can contain values for some or all of its columns. INSERT INTO can be combined with a SELECT to insert records. INSERT INTO Artist (ArtistId, Name) VALUES (99999, 'Joshua Nahum, Superstar');

Multiple Values You can insert multiple rows with a single INSERT statement: INSERT INTO Artist (ArtistId, Name) VALUES (99998, 'Tyler'), (99997, 'Grant');

insert into select You can also use a SELECT clause to generate the needed rows, but you need to return the correct column types and order. INSERT INTO Artist (ArtistId, Name) SELECT Employee.EmployeeId + 1000000, Employee.FirstName FROM Employee;

update The UPDATE statement updates data values in a database. UPDATE can update one or more records in a table. Use the WHERE clause to UPDATE only specific records. UPDATE Album SET Title = Title || '!'; UPDATE Track SET Milliseconds = 0 WHERE Name LIKE '%rap%'; UPDATE Track SET Milliseconds = 0, Bytes = 0 WHERE Name LIKE '%rap%';

What does the || operator do? Concatenates two TEXT values Combines two TEXT values Adds two TEXT values Aren't the three above all the same? (They are)

Delete DELETE permanently removes records from a table. DELETE can delete one or more records in a table. Use the WHERE clause to DELETE only specific records. DELETE FROM Genre; -- removes all rows DELETE FROM Genre WHERE Name LIKE '%rap%'; --removes some rows

autoincrement SQLite AUTOINCREMENT is a keyword used for auto incrementing a value of a field in the table. We can auto increment a field value by using AUTOINCREMENT keyword when creating a table with specific column name to auto incrementing it. The keyword AUTOINCREMENT can be used with a INTEGER PRIMARY KEY field only. CREATE TABLE table_name ( column1 INTEGER PRIMARY KEY AUTOINCREMENT, column2 datatype, column3 datatype, ..... columnN datatype);

Should I use it? From https://www.sqlite.org/autoinc.html: "The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed." If a column is INTEGER PRIMARY KEY, it already will autofill a unique value if a value isn't provided. The only difference is AUTOINCREMENT guarantees monotonically increasing values, instead of just unique.