CS6320 - SQL
The Structured Query Language (SQL) Composed of two categories: Data Definition create database create table drop database Data Manipulation used to manipulate the data select delete update
Data Definition CREATE TABLE - allows you to create a table definition in a database CREATE DATABASE - allows you to create a database DROP TABLE - removes a table from a database ALTER TABLE - modifies the definition of a table in a database
Create Table Example 1: Example 2: CREATE TABLE CUSTOMER( LAST_NAME varchar2(30) not null, STATE_CD varchar(2), SALES number); Example 2: CREATE TABLE PRODUCTS( NAME VARCHAR2(30) NOT NULL, DESCRIPTION VARCHAR2(300), PRICE NUMBER(4,2) ) TABLESPACE PRODUCTSPACE STORAGE(INITIAL 25K NEXT 25K MINEXTENTS 1);
Alter Table Add column ALTER TABLE CUSTOMER ADD TAX_EXEMPT_ID VARCHAR2(20); Drop column ALTER TABLE CUSTOMER DROP COLUMN SALES;
Data Manipulation Language SELECT - query the database select * from customer where id > 1001 INSERT - adds new rows to a table. Insert into customer values (1009, ‘John Doe’) DELETE - removes a specified row delete from customer where amount = 100 UPDATE - modifies an existing row update customers set amount = 10 where id > 1003
Select Get all data from table Get column Distribute data from table SELECT * FROM TABLE Get column Distribute data from table SELECT DISTRIBUTE FROM TABLE Get all data where…. SELECT * FROM TABLE WHERE NAME IS 'BUTCH GREWE'
Insert Add following entry to table…order of data fields MUST be the same as when created table INSERT INTO TABLE VALUES ('JAMES BOND', '1 EIFFEL TOWER', 'PARIS', 'FRANCE','SPY SOFTWARE')
Delete Remove entries where…. DELETE FROM TABLE WHERE AGE=10
Describe Get meta-data DESCRIBE TABLE