150 likes | 288 Views
Intro to SQL. Log on and set password. Exit, Rollback, Commit. Case sensitivity, spacing, end of sentence. Spacing not relevant BUT… no spaces in an attribute name or table name Oracle commands keywords, table names, and attribute names not case sensitive
E N D
Log on and set password Intro to SQL| MIS 2502
Exit, Rollback, Commit Intro to SQL| MIS 2502
Case sensitivity, spacing, end of sentence • Spacing not relevant • BUT… no spaces in an attribute name or table name • Oracle commands keywords, table names, and attribute names not case sensitive • Entering and retrieving string values are case sensitive • To end sentence -> ; Intro to SQL| MIS 2502
USE NOTEPAD! • SQL plus’ editor is a pain! • Enter code in notepad and then copy and paste at prompt in SQL plus • Hit enter to run command Intro to SQL| MIS 2502
Delete a table • Drop table • Cascade constraints!!! – enforces that no delete anomolies • Drop table manager cascade constraints; Intro to SQL| MIS 2502
Important data types… • Char • Varchar • Number • Date • Integer Intro to SQL| MIS 2502
Create table syntax CREATE TABLE <tablename> (<fieldname> <data declaration> … [CONSTRAINT <integrity constraint declaration>… ); CREATE TABLE bank_customer ( Customer_ID NUMBER(5) constraint customer_id primary key, Customer_LastName VARCHAR2(30) not null, Customer_FirstName VARCHAR2(30) not null, Customer_MI Char(1) null, Add1 VARCHAR2(30) not null, City VARCHAR2(25) not null, State CHAR(2) not null, Zip CHAR(5) not null ); Don’t need not null since PK cannot be null No comma since last attribute Intro to SQL| MIS 2502
To show a table design - Describe • Describe tablename -> describe customer Intro to SQL| MIS 2502
Alter • Can change following in a table: • attribute names, size, data types • Remove and add attributes • Cannot change a field from null to not null. • For FK – can’t reference a field that doesn’t exist. That’s why I’ve had you add the tables and attributes first and then reference them with the Alter command Intro to SQL| MIS 2502
Alter table – adding/ modifying attributes Intro to SQL| MIS 2502
Alter – Constraints Intro to SQL| MIS 2502
Alter – Constraints Intro to SQL| MIS 2502
Note - Strings • Text must be entered in single quotes… ‘PA’ Intro to SQL| MIS 2502