Tonight’s Lecture chapter 3. A Guide to MySQL2 Using MySQL Reference Manual to Get Help Can access online

Slides:



Advertisements
Similar presentations
Session 2Introduction to Database Technology Data Types and Table Creation.
Advertisements

9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
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.
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”
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Oracle Data Definition Language (DDL)
Final Review. put the following items in their correct order where order by select having group by from select from where group by having order by.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
1 An Introduction to SQL. 2 Objectives  Understand the concepts and terminology associated with relational databases  Create and run SQL commands 
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
A Guide to SQL, Eighth Edition Chapter Two Database Design Fundamentals.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
1 A Guide to MySQL 2 Database Design Fundamentals.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
DATA MANIPULATION andCONTROL
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 A Guide to SQL Chapter 2. 2 Introduction Mid-1970s: SQL developed under the name SEQUEL at IBM by San Jose research facilities to be the data manipulation.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
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.
Variables and control statements in PL\SQL Chapter 10.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Database Programming Sections 9 & 10 – DDL Data Definition Language,
Chapter 3 Table Creation and Management Oracle 10g: SQL.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
 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.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
3 A Guide to MySQL.
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
Chapter 5 Introduction to SQL.
A Guide to SQL, Eighth Edition
SQL: Schema Definition and Constraints Chapter 6 week 6
SQL Creating and Managing Tables
SQL Creating and Managing Tables
SQL Creating and Managing Tables
SQL data definition using Oracle
variables and control statements in PL\SQL
Oracle Data Definition Language (DDL)
Yong Choi School of Business CSU, Bakersfield
Chapter 2: Creating And Modifying Database Tables
IST 318 Database Administration
SQL (Structured Query Language)
Presentation transcript:

Tonight’s Lecture chapter 3

A Guide to MySQL2 Using MySQL Reference Manual to Get Help Can access online

A Guide to MySQL3 Describing a Table

In Oracle DESC table_name example: DESC h_book

DDL Stands for Data Definition Language – create statements – drop statements – alter statements

A Guide to MySQL6 Creating a Database Must create a database before creating tables Use CREATE DATABASE command Include database name

A Guide to MySQL7 Changing the Default Database Default database: database to which all subsequent commands pertain USE command, followed by database name: – Changes the default database – Execute at the start of every session

You’re changing your default database by selecting your user database from the drop down in PhpMyAdmin

A Guide to MySQL9 Creating a Table Describe the layout of each table in the database Use CREATE TABLE command TABLE is followed by the table name Follow this with the names and data types of the columns in the table Data types define type and size of data

A Guide to MySQL10 Table and Column Name Restrictions Names cannot exceed 18 characters Must start with a letter Can contain letters, numbers, and underscores (_) Cannot contain spaces

Avoid using reserved words as names of your database objects Reserved words can differ from database platform to database platform MySQL reserved word examples - select - numeric - database - group

A Guide to MySQL12 Implementation of Nulls Use NOT NULL clause in CREATE TABLE command to exclude the use of nulls in a column Default is to allow null values If a column is defined as NOT NULL, system will reject any attempt to store a null value there

CREATE TABLE a_marina ( MARINA_NUM char(4) NOT NULL, NAME char(20) NULL, ADDRESS char(15) NULL, CITY char(15) NULL, STATE char(2) NULL, ZIP char(5) NULL, PRIMARY KEY (MARINA_NUM) ) FieldTypeNullKeyDefaultExtra MARINA_NUMchar(4)NOPRI NAMEchar(20)YES ADDRESSchar(15)YES CITYchar(15)YES STATEchar(2)YES ZIPchar(5)YES What will this SQL statement do?

CREATE TABLE a_marina ( MARINA_NUM char(4) NOT NULL, NAME char(20), ADDRESS char(15), CITY char(15), STATE char(2), ZIP char(5), PRIMARY KEY (MARINA_NUM) ) FieldTypeNullKeyDefaultExtra MARINA_NUMchar(4)NOPRI NAMEchar(20)YES ADDRESSchar(15)YES CITYchar(15)YES STATEchar(2)YES ZIPchar(5)YES What will this SQL statement do?

CREATE TABLE a_marina ( MARINA_NUM char(4) NOT NULL, NAME char(20), ADDRESS char(15), CITY char(15), STATE char(2), ZIP char(5) ) FieldTypeNullKeyDefaultExtra MARINA_NUMchar(4)NO NAMEchar(20)YES ADDRESSchar(15)YES CITYchar(15)YES STATEchar(2)YES ZIPchar(5)YES What will this SQL statement do?

CREATE TABLE a_marina ( MARINA_NUM char(4) NOT NULL, NAME char(20), ADDRESS char(15), CITY char(15), STATE char(2), ZIP ) What will this SQL statement do? ERROR We did not specify a datatype for the column ZIP

FieldTypeNullKeyDefaultExtra OWNER_NUMchar(4)NOPRI LAST_NAMEchar(50)YES FIRST_NAMEchar(20)YES ADDRESSchar(15)YES CITYchar(15)YES STATEchar(2)YES ZIPchar(5)YES Write the SQL that will create an A_OWNER table with the following structure: CREATE TABLE a_owner ( OWNER_NUM char(4) NOT NULL, LAST_NAME char(50) NULL, FIRST_NAME char(20) NULL, ADDRESS char(15) NULL, CITY char(15) NULL, STATE char(2) NULL, ZIP char(5) NULL, PRIMARY KEY (OWNER_NUM) )

FieldTypeNullKeyDefaultExtra employee_idvarchar(10)YES namevarchar(100)YES manager_idvarchar(10)YES CREATE TABLE employees ( employee_id varchar(10) NULL, name varchar(100) NULL, manager_id varchar(10) NULL ) Write the SQL that will create an EMPLOYEES table with the following structure:

FieldTypeNullKeyDefaultExtra ORDER_NUMchar(5)NOPRI PART_NUMchar(4)NOPRI NUM_ORDEREDdecimal(3,0)YES QUOTED_PRICEdecimal(6,2)YES CREATE TABLE p_order_line ( ORDER_NUM char(5) NOT NULL, PART_NUM char(4) NOT NULL, NUM_ORDERED decimal(3,0) NULL, QUOTED_PRICE decimal(6,2) NULL, PRIMARY KEY (ORDER_NUM,PART_NUM) ) Write the SQL that will create an P_ORDER_LINE table with the following structure:

FieldTypeNullKeyDefaultExtra BOOK_CODEchar(4)NOPRI BRANCH_NUMdecimal(2,0)NOPRI0 ON_HANDdecimal(2,0)YES CREATE TABLE h_inventory ( BOOK_CODE char(4) NOT NULL, BRANCH_NUM decimal(2,0) NOT NULL default 0, ON_HAND decimal(2,0) NULL, PRIMARY KEY (BOOK_CODE,BRANCH_NUM) ) Write the SQL that will create an H_INVENTORY table with the following structure:

CREATE TABLE h_book ( BOOK_CODE char(4) NOT NULL, TITLE char(40) NULL, PUBLISHER_CODE char(3) NULL, TYPE char(3) NULL, PRICE decimal(4,2) NULL, PAPERBACK char(1) NULL, PRIMARY KEY (BOOK_CODE) ) Write the SQL that will create an H_BOOK table with the following structure: FieldTypeNullKeyDefaultExtra BOOK_CODEchar(4)NOPRI TITLEchar(40)YES PUBLISHER_CODEchar(3)YES TYPEchar(3)YES PRICEdecimal(4,2)YES PAPERBACKchar(1)YES

CREATE TABLE p_rep ( REP_NUM char(2) NOT NULL, LAST_NAME char(15) NULL, FIRST_NAME char(15) NULL, STREET char(15) NULL, CITY char(15) NULL, STATE char(2) NULL, ZIP char(5) NULL, COMMISSION decimal(7,2) NULL, RATE decimal(3,2) NULL, PRIMARY KEY (REP_NUM) ) Write the SQL that will create an P_REP table with the following structure: FieldTypeNullKeyDefaultExtra REP_NUMchar(2)NOPRI LAST_NAMEchar(15)YES FIRST_NAMEchar(15)YES STREETchar(15)YES CITYchar(15)YES STATEchar(2)YES ZIPchar(5)YES COMMISSIONdecimal(7,2)YES RATEdecimal(3,2)YES

A Guide to MySQL23 Dropping a Table Can correct errors by dropping (deleting) a table and starting over Useful when table is created before errors are discovered Command is followed by the table to be dropped and a semicolon Any data in table also deleted

drop table a_owner be careful with drop statements

What is DDL?

A Guide to MySQL26 Adding Rows to a Table INSERT command : – INSERT INTO followed by table name – VALUES command followed by specific values in parentheses – Values for character columns in single quotation marks

A Guide to MySQL27 The Insert Command