Chapter # 7 Introduction to Structured Query Language (SQL) Part I.

Slides:



Advertisements
Similar presentations
Introduction to Structured Query Language (SQL)
Advertisements

1 SQL Server Management Studio SQL DDL CREATE TABLE Constraints ALTER TABLE DROP TABLE The GUI way Steen Jensen, autumn 2013.
7 7 SQL Data Definition 4Spread throughout chapter 7.
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
3 3 Chapter 3 Structured Query Language (SQL) Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
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.
5 Chapter 5 Structured Query Language (SQL1) Revision.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Introduction to SQL J.-S. Chou Assistant Professor.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
6 1 Chapter 6 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Database Systems: Design, Implementation, and Management Tenth Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
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.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
1 Chapter 6 Structured Query Language (SQL) DATABASE MANAGEMENT SYSTEM.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
CDT/1 Creating data tables and Referential Integrity Objective –To learn about the data constraints supported by SQL2 –To be able to relate tables together.
Introduction to Oracle. Before Computerized Database Organization use a set of data files to store each individual data. – The file contains individual.
Database Languages.
Chapter 5 Introduction to SQL.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
The Basics of Data Manipulation
Insert, Update and the rest…
ORACLE SQL Developer & SQLPLUS Statements
STRUCTURED QUERY LANGUAGE
Chapter 8 Working with Databases and MySQL
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
The Basics of Data Manipulation
مقدمة في قواعد البيانات
Chapter 7 Introduction to Structured Query Language (SQL)
A Guide to SQL, Eighth Edition
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Presentation transcript:

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

Introduction to SQL SQL functions fit into two broad categories: Data definition language Data manipulation language Basic command set has vocabulary of less than 100 words American National Standards Institute (ANSI) prescribes a standard SQL Several SQL dialects exist

SQL Family SQL (Structured Query Language) Data Definition Language (DDL) CREATE ALTER DROP Data Manipulation Language (DML) SELECT INSERT UPDATE DELETE Data Control Language (DCL) GRANT REVOKE

Data Definition Commands The database model In this chapter, a simple database with these tables is used to illustrate commands: CUSTOMER INVOICE LINE PRODUCT VENDOR Focus on PRODUCT and VENDOR tables

Data Definition Commands (2)

Creating the Database Two tasks must be completed: Create database structure Create tables that will hold end-user data First task: RDBMS creates physical files that will hold database Differs substantially from one RDBMS to another CREATE DATABASE <DATABASENAME>; CREATE TABLE states ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, state CHAR(25), population INT(9) );

The Database Schema Authentication DBMS verifies that only registered users are able to access database Log on to RDBMS using user ID and password created by database administrator CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; GRANT ALL ON db1.* TO 'jeffrey'@'localhost'; Schema Group of database objects that are related to each other

Data Types Data type selection is usually dictated by nature of data and by intended use Supported data types: Number(L,D), Integer, Smallint, Decimal(L,D) Char(L), Varchar(L), Varchar2(L) Date, Time, Timestamp Real, Double, Float Interval day to hour Many other types

Creating Table Structures Use one line per column (attribute) definition Use spaces to line up attribute characteristics and constraints Table and attribute names are capitalized NOT NULL specification UNIQUE specification Primary key attributes contain both a NOT NULL and a UNIQUE specification RDBMS will automatically enforce referential integrity for foreign keys Command sequence ends with semicolon

Creating Table Structures (Example)

SQL Constraints NOT NULL constraint Ensures that column does not accept nulls UNIQUE constraint Ensures that all values in column are unique DEFAULT constraint Assigns value to attribute when a new row is added to table. The end user may, of course, enter a value other than the default value. CHECK constraint Validates data when attribute value is entered

SQL Constraints In this chapter, Oracle is used to illustrate SQL constraints. For example, note that the following SQL command sequence uses the DEFAULT and CHECK constraints to define the table named CUSTOMER.

SQL Indexes When primary key is declared, DBMS automatically creates unique index Often need additional indexes Using CREATE INDEX command, SQL indexes can be created on basis of any selected attribute Using the CREATE INDEX command, SQL indexes can be created on the basis of any selected attribute. The syntax is: CREATE [UNIQUE] INDEX indexname ON tablename(column1 [, column2])

SQL Indexes For example, based on the attribute P_INDATE stored in the PRODUCT table, the following command creates an index named P_INDATEX: CREATE INDEX P_INDATEX ON PRODUCT(P_INDATE); Using the UNIQUE index qualifier, you can even create an index that prevents you from using a value that has been used before. Such a feature is especially useful when the index attribute is a candidate key whose values must not be duplicated: CREATE UNIQUE INDEX P_CODEX ON PRODUCT(P_CODE);

Data Manipulation Commands INSERT SELECT UPDATE DELETE ROLLBACK COMMIT

Adding Table Rows Example INSERT Used to enter data into table Basic Syntax: Example INSERT INTO columnname VALUES (value1, value2, … , valueN); INSERT INTO VENDORVALUES (21225,'Bryson, Inc.','Smithson','615','223-3234','TN','Y');

Adding Table Rows (2) When entering values, notice that: Row contents are entered between parentheses Character and date values are entered between apostrophes Numerical entries are not enclosed in apostrophes Attribute entries are separated by commas A value is required for each column Use NULL for unknown values INSERT INTO PRODUCTVALUES ('BRT-345','Titanium drill bit','18-Oct-09', 75, 10, 4.50, 0.06, NULL);

Saving Table Changes Changes made to table contents are not physically saved on disk until: Database is closed Program is closed COMMIT command is used Syntax: NOTE TO MS ACCESS USERS MS Access doesn't support the COMMIT command because it automatically saves changes after the execution of each SQL command. COMMIT [WORK]; Will permanently save any changes made to any table in the database

Listing (Showing) Table Rows SELECT Used to list contents of table Basic Syntax: SELECT columnlist FROM tablename; Example: SELECT * FROM PRODUCT; Columnlist represents one or more attributes, separated by commas Asterisk can be used as wildcard character to list all attributes

THE END