Structured Query Language - SQL Carol Wolf Computer Science.

Slides:



Advertisements
Similar presentations
SQL Rohit Khokher.
Advertisements

Sanjay Goel, School of Business, University at Albany, SUNY 1 SQL- Data Definition Language ITM 692 Sanjay Goel.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
Structured query language This is a presentation by JOSEPH ESTRada on the beauty of Structured Query Language.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
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”
©Silberschatz, Korth and Sudarshan3.1Database System Concepts - 6 th Edition SQL Schema Changes and table updates instructor teaches.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Database Systems Lecture 5 Natasha Alechina
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Basis Data Terapan Yoannita. SQL Server Data Types Character strings: Data typeDescriptionStorage char(n)Fixed-length character string. Maximum 8,000.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
CSC 2720 Building Web Applications Database and SQL.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Fox MIS Spring 2011 Database Week 5 SQL basics SELECT, INSERT, UPDATE, DELETE.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Ennis-Cole, AC 2.01, CECS Maintaining A Database By: Dr. Ennis-Cole.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Relational Databases and SQL The relational model and the most common SQL commands.
Choosing Data Types Database Administration Fundamentals
Creating Database Objects
CS SQL.
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
TABLES AND INDEXES Ashima Wadhwa.
Insert, Update and the rest…
CS 480: Database Systems Lecture 13 February 13,2013.
Data Definition and Data Types
STRUCTURED QUERY LANGUAGE
Creating Tables & Inserting Values Using SQL
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS1222 Using Relational Databases and SQL
Structured Query Language Path from Unorganized to Organized….
Creating Database Objects
CS122 Using Relational Databases and SQL
Database Instructor: Bei Kang.
JDBC II IS
SQL (Structured Query Language)
Presentation transcript:

Structured Query Language - SQL Carol Wolf Computer Science

SQL  Used for relational databases, which consist of rows and columns.  SQL is not case sensitive. Queries are usually in all upper case.  These slides will use upper case only for the first letter.  In Rails, you can use find_by_sql(…).  The query inside the parentheses is in quotation marks.  You have to debug the queries yourself.

The Select Query  "Select * From courses "  This returns all the rows in the courses table.  "Select * From courses Where Name Like 'A%'"  This will narrow the search down to courses with names beginning with A.  "Select * From courses Where Name Between 'A%' And 'C%'"  This returns all the courses with names beginning with A, B and C.  If the name occurs several times in the table, all those rows will be returned. To restrict this to the first such row, you add.first to the query.

Select and variables  "Select * From courses Where Name = '" + name + "'"  Variables that are strings must be enclosed in quotation marks.  This usually requires quotes (single) within quotes (double).  This is a major drawback to SQL.  "Select * From courses Where credits >= " + amount  Variables that are numeric do not take quotation marks.  These are definitely easier to manage.

Update Queries - Insert  "Insert into courses Values ('CS122', 'Programming II', 4) "  The string fields must be surrounded by quotes.  The numeric field does not have them.  "Insert Into courses Values ('" + number + "', '" + name + "', " + credits) "  In order to use string variables, you have to have quotes around the variables.  These are added in using the plus sign for concatenation.  "', '" – This shows a double quote followed by a single quote followed by a comma, etc.  Inserting more than two or three string variables is hard on the eyes.  If insert fails, it returns 0, otherwise it returns the number of rows inserted.

Update Query - Delete  "Delete From courses Where id = '" + key_id + "'“  This deletes the row in the table with the key id.  Here the key id is a variable.

Update  "Update course Set credits = 4 Where id = 5"  This changes the credits for the course with id 5.  "Update courses Set credits = " + new_credits + " Where id = " + id + "  This changes credits using variables.  "Update course Set number = 'CS122', credits = 4 Where id = 5"  This changes two fields at the same time.  "Update course Set number = " + new_number + ", credits = " + new_credits + " Where id = + id + “  Change two fields using variables.

Create and Alter  These change the database itself.  Create adds a new table to the database.  Alter adds or drops a column.  "Create Table professors (id integer, name varchar, varchar, department varchar) "  This adds a new table with four columns.  "Alter Table courses Add professor varchar(20)"  This adds a new column to an existing table.  "Alter Table courses Drop Column credits"  This removes the credits column from the table.

Datatypes for database queries integer(size) int(size) smallint(size) Holds integers only. The maximum number of digits is specified in parenthesis. decimal(size,d) numeric(size,d) Holds numbers with fractions. The maximum number of digits is specified in "size". The maximum number of digits to the right of the decimal is specified in "d". float(n) real double Floating point number with n binary digits of precisions. 32-bit floating point number. 64-bit floating point number. char(size)Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. varchar(size)Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. date(yyyymmdd)Holds a date.