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.

Slides:



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

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
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 Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
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.
Database Management System LICT 3011 Eyad H. Elshami.
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.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CSC 2720 Building Web Applications Database and SQL.
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
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.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
SQL for Database Construction and Application Processing
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Visual Programing SQL Overview Section 1.
SQL Structured Query Language. Aims  To introduce the implementation of a Physical design using SQL.  To introduce SQL Data Definition Language (DDL).
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.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
1 Chapter 2: Creating and Modifying Database Objects.
1 SQL Insert Update Delete Create table Alter table.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
SY306 Web and Databases for Cyber Operations Databases - The Relational Model.
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)
At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints.
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Working with MySQL A290/A590, Fall /07/2014.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
CS SQL.
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
SQL: Schema Definition and Constraints Chapter 6 week 6
Referential Integrity MySQL
CS311 Database Management system
Lecturer: Mukhtar Mohamed Ali “Hakaale”
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Database Management System
CS1222 Using Relational Databases and SQL
Data Definition Language
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Instructor: Samia arshad
CS122 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
SQL NOT NULL Constraint
SQL (Structured Query Language)
Presentation transcript:

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 sensitive But user identifier names ARE case sensitive

5/27/2016Chapter 33 of 19 Database Check what databases you have Check what databases you have mysql> SHOW DATABASES; mysql> SHOW DATABASES; Create a database Create a database mysql> CREATE DATABASE name; mysql> CREATE DATABASE name; Delete a database Delete a database mysql> DROP DATABASE name; mysql> DROP DATABASE name; Open a database to use Open a database to use mysql> USE name; mysql> USE name;

5/27/2016Chapter 34 of 19 Tables Check what tables you have in the database Check what tables you have in the database mysql> SHOW TABLES; mysql> SHOW TABLES;

5/27/2016Chapter 35 of 19 Tables Create a table Create a table mysql> CREATE TABLE potluck ( mysql> CREATE TABLE potluck ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), food VARCHAR(30), confirmed CHAR(1), signup_date DATE);

5/27/2016Chapter 36 of 19 Tables Check the table structure Check the table structure mysql> DESCRIBE potluck; mysql> DESCRIBE potluck;

5/27/2016Chapter 37 of 19 Add a Column Add a new column at the end of the table Add a new column at the end of the table ALTER TABLE potluck ADD VARCHAR(40); ALTER TABLE potluck ADD VARCHAR(40);

5/27/2016Chapter 38 of 19 Add a Column Add a new column at a specific location in the table Add a new column at a specific location in the table ALTER TABLE potluck ADD VARCHAR(40) AFTER name; ALTER TABLE potluck ADD VARCHAR(40) AFTER name;

5/27/2016Chapter 39 of 19 Delete a Column Delete a column from the table Delete a column from the table ALTER TABLE potluck DROP ; ALTER TABLE potluck DROP ;

5/27/2016Chapter 310 of 19 Add Record Add a record into a table Add a record into a table INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "John", "Casserole","Y", ' '); INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "John", "Casserole","Y", ' ');

5/27/2016Chapter 311 of 19 List Records List the records in a table List the records in a table SELECT * FROM potluck; SELECT * FROM potluck;

5/27/2016Chapter 312 of 19 Update Record Update a record in a table Update a record in a table UPDATE `potluck` SET `confirmed` = 'Y' WHERE `potluck`.`name` = 'Sandy'; UPDATE `potluck` SET `confirmed` = 'Y' WHERE `potluck`.`name` = 'Sandy';

5/27/2016Chapter 313 of 19 Delete Record Delete a record from a table Delete a record from a table DELETE from potluck where name='Sandy'; DELETE from potluck where name='Sandy';

5/27/2016Chapter 314 of 19 Create Foreign Key Create a foreign key Create a foreign key CONSTRAINT constraint_name FOREIGN KEY foreign_key_name (columns) REFERENCES parent_table(columns) ON DELETE action ON UPDATE action

5/27/2016Chapter 315 of 19 Create Foreign Key CREATE TABLE categories( cat_id int not null auto_increment primary key, cat_id int not null auto_increment primary key, cat_name varchar(255) not null, cat_name varchar(255) not null, cat_description text cat_description text ) ;

5/27/2016Chapter 316 of 19 Create Foreign Key CREATE TABLE products( prd_id int not null auto_increment primary key, prd_id int not null auto_increment primary key, prd_name varchar(355) not null, prd_name varchar(355) not null, prd_price decimal, prd_price decimal, cat_id int not null, cat_id int not null, FOREIGN KEY fk_cat(cat_id) FOREIGN KEY fk_cat(cat_id) REFERENCES categories(cat_id) REFERENCES categories(cat_id) ON UPDATE CASCADE ON UPDATE CASCADE ON DELETE RESTRICT ON DELETE RESTRICT);

5/27/2016Chapter 317 of 19 Show Foreign Key Show the foreign key created in table Show the foreign key created in table SHOW CREATE TABLE table_name

5/27/2016Chapter 318 of 19 Add Foreign Key Add a foreign key to an existing table Add a foreign key to an existing table ALTER table_name ADD CONSTRAINT constraint_name FOREIGN KEY foreign_key_name (columns) REFERENCES parent_table(columns) ON DELETE action ON UPDATE action

5/27/2016Chapter 319 of 19 Add Foreign Key ALTER TABLE products( ADD FOREIGN KEY fk_vendor(vdr_id) ADD FOREIGN KEY fk_vendor(vdr_id) REFERENCES vendors(vdr_id) REFERENCES vendors(vdr_id) ON UPDATE CASCADE ON UPDATE CASCADE ON DELETE RESTRICT ON DELETE RESTRICT);

5/27/2016Chapter 320 of 19 Drop Foreign Key Drop foreign key from table Drop foreign key from table ALTER table_name DROP FOREIGN KEY constraint_name