bonus material on sql

16
1

Upload: masriffa

Post on 04-Sep-2015

226 views

Category:

Documents


0 download

DESCRIPTION

About SQL

TRANSCRIPT

  • 1

  • 2

    Bonus Material: SQL

  • collection of information

    structure expressed in columns

    data expressed in rows

    3

  • reduces wasted space

    reduces repetition of information

    enforces data integrity

    maximizes efficiency

    4

  • structured query language

    can be used to define db

    used for manipulating data

    5

  • data definition create alter drop

    data manipulation insert select update delete

    6

  • It is usually a good idea to SAVE your CREATE statements in case you ever need to recreate your tables.

    Use ALTER statements judiciously and only after thorough consideration. ALTER can break normalization, and have other undesired results.

    Use DROP statements even more carefully. Make sure you have a good backup first.

    7

  • create database

    CREATE DATABASE database_name

    create table

    CREATE TABLE table_name ( column1 data_type, column2 data_type, etc... );

    8

  • CREATE TABLE students ( student_id int(9), first_name varchar(30), middle_name varchar(30), last_name varchar(30), address1 varchar(40), address2 varchar(40), city varchar(35), state char(2), zip int(5), zip4 int(4) );

    9

  • DROP TABLE table_name;

    DROP TABLE students;

    http://xkcd.com/327/ 10

  • INSERT INTO table_name ( column1, column2, ... ) VALUES ( data_value1, data_value2, ... );

    11

  • INSERT INTO students ( column1, column2, ... ) VALUES ( data_value1, data_value2, ... );

    12

  • SELECT column_name(s)

    FROM table_name(s)

    WHERE condition(s);

    13

  • UPDATE table_name

    SET column1=new_data_value1, column2=new_data_value2, ...

    WHERE condition(s);

    14

  • DELETE FROM table_name

    WHERE condition(s);

    15

  • 16