CS122 Using Relational Databases and SQL

Slides:



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

Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Structured Query Language - SQL Carol Wolf Computer Science.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
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”
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
ASP.NET Programming with C# and SQL Server First Edition
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
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.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Fundamentals of DBMS Notes-1.
CS SQL.
CS320 Web and Internet Programming SQL and MySQL
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Data Definition and Data Types
SQL: Schema Definition and Constraints Chapter 6 week 6
The Basics of Data Manipulation
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Insert, Update and the rest…
SQL – CRUD.
CS1222 Using Relational Databases and SQL
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
Structured Query Language (SQL) William Klingelsmith
Lecturer: Mukhtar Mohamed Ali “Hakaale”
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
CS1222 Using Relational Databases and SQL
Structured Query Language
Creating Tables & Inserting Values Using SQL
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter 2: Creating And Modifying Database Tables
CS1222 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
Data Definition Language
Data Definition Language
CS122 Using Relational Databases and SQL
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
IST 318 Database Administration
CS3220 Web and Internet Programming SQL and MySQL
CS1222 Using Relational Databases and SQL
Structured Query Language Path from Unorganized to Organized….
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
SQL (Structured Query Language)
CS1222 Using Relational Databases and SQL
Presentation transcript:

CS122 Using Relational Databases and SQL 10/22/17 10/16/17 CS122 Using Relational Databases and SQL 8. Data Manipulation and Definition Daniel Firpo Department of Computer Science California State University, Los Angeles 1

Outline Data manipulation Data definition INSERT DELETE UPDATE 10/22/17 10/16/17 Outline Data manipulation INSERT DELETE UPDATE Data definition CREATE a table MODIFY a table DELETE a table 8. Data Manipulation & Definition CS1222_F2018 8-2 2

Database Definition Language (DDL) 1/17/2019 Database Definition Language (DDL) Subset of SQL commands to create and modify database objects Can create an entire database using SQL rather than a graphical user interface With DDL you gain more control over exactly what database objects are built and what they are named DDL saved into a script can be easily ported from one database installation to another 8. Data Manipulation & Definition CS1222_F2018

8. Data Manipulation & Definition CS1222_F2018 1/17/2019 Naming Tips Use consistent names Do not include spaces inside your table or fields Avoid the use of SQL reserved words and punctuation marks in table and field names  Keep names short, but long enough to be descriptive Be consistent in your use of abbreviations Name primary key and foreign key fields consistently Avoid generic field names, such as ID or Date 8. Data Manipulation & Definition CS1222_F2018

Databases MySQL Instance of MySQL running on a server computer can contain multiple databases New MySQL database can be created with Create Database followed by the name to be used for the new database or Create Database If Not Exists followed by the name of the database There are no other options for the Create Database command Can switch between databases by typing Use followed by the database name

8. Data Manipulation & Definition CS1222_F2018 1/17/2019 Creating a Table Null means that the field may contain null (empty) values. Not Null means that the field cannot contain null values. Syntax CREATE TABLE tablename ( Fieldname1 DataType NULL | NOT NULL, Fieldname2 DataType NULL | NOT NULL ) Please refer to earlier slides for datatypes in MySQL 8. Data Manipulation & Definition CS1222_F2018

Creating a Table: Example 1/17/2019 Create a table called Contracts with the ArtistID from the Artists table and a ContractDate field CREATE TABLE tblContracts ( ArtistID Integer NOT NULL, ContractDate DateTime NOT NULL ) A left parenthesis comes before the first field in the list. Each field entry except the last one is followed by a comma. The last field in the list is followed by a right parenthesis. 8. Data Manipulation & Definition CS1222_F2018

8. Data Manipulation & Definition CS1222_F2018 1/17/2019 Dropping a Table Syntax DROP Table tablename Example: Remove the tblContracts table from the database DROP Table tblContracts 8. Data Manipulation & Definition CS1222_F2018

Adding Columns to an Existing Table 1/17/2019 Adding Columns to an Existing Table Syntax ALTER TABLE tablename ADD fieldname DataType NULL | NOT NULL 8. Data Manipulation & Definition CS1222_F2018

Adding Columns to an Existing Table 1/17/2019 Adding Columns to an Existing Table Add a text field called ContractType with a length of 10 to the tblContracts table ALTER TABLE tblContracts ADD ContractType VarChar(10) NULL 8. Data Manipulation & Definition CS1222_F2018

Altering Existing Columns in a Table 1/17/2019 Altering Existing Columns in a Table Syntax ALTER TABLE tablename MODIFY fieldname DataType NULL | NOT NULL 8. Data Manipulation & Definition CS1222_F2018

Altering Existing Columns in a Table: Example 1/17/2019 Altering Existing Columns in a Table: Example Change the length on the ContractType field to 15 in the tblContracts table ALTER TABLE tblContracts MODIFY ContractType VARCHAR(15) NULL 8. Data Manipulation & Definition CS1222_F2018

8. Data Manipulation & Definition CS1222_F2018 1/17/2019 Dropping a Column Syntax ALTER TABLE tablename DROP COLUMN columnname Example: Remove the Contracttype column from the tblContracts table ALTER TABLE tblContracts DROP COLUMN ContractType 8. Data Manipulation & Definition CS1222_F2018

Identity Columns and Sequences 1/17/2019 Identity Columns and Sequences Techniques to automatically generate a sequential number with each row that is inserted Never have to insert a value to it, but it will always be unique within that table Make excellent primary keys in cases where there is no naturally occurring primary key 8. Data Manipulation & Definition CS1222_F2018

Defining an Identity Column 1/17/2019 Defining an Identity Column CREATE TABLE tblX ( ID INT auto_increment Primary key, anotherfield int NULL ) 8. Data Manipulation & Definition CS1222_F2018

Sequences Vs. Guid Columns An identity column (or sequence) is unique within a given a table in a given database on a given server With distributed database, identity column may not\be unique across every instance of the table One solution is to use the identity column in conjunction with a locationID as the primary key Another solution Globally Unique Identifier (GUID), which is supported in some databases A GUID is a 16-byte ID guaranteed to be unique across every instance of a distributed database GUIDs are cumbersome to work with: C1C5FCE2-879E-4A96-B845- 9F3FC4A10EC8