2/19/20131DAY2Session1DataDefinitionLanguage(DDL).DataModificationLanguage(DML).Session2TransactionControlLanguage(TCL).DataControlLanguage(DCL).Constraints.DATADEFINITIONLANGUAGE2/19/20132DataDefinitionLanguageNamingRulesDataDefinitionLanguage2/19/20133DataDefinitionLanguageDefaultOptionDataDefinitionLanguageCreatingTableConformationOfCreatedtable2/19/20134DataDefinitionLanguageKindsOfTablesInADataBaseDataDefinitionLanguageViewingInfofromDictionaryTables2/19/20135DataTypes:CreatingTableUsingSubquerySyntaxSQLCREATETABLEdept1ASSELECT*FROMdept;2/19/20136CreatingTableUsingSubquery(SelectiveColumns)SQLCREATETABLEemp1ASSELECTename,job,salFROMemp;UsingAlterTableStatement2/19/20137UsingAlterTableStatementAddingaNewColumnSyntax:SQLALTERTABLEEMP1ADDdnamevarchar2(15)default‘Accounts’;UsingAlterTableStatementModifyingaColumnSyntax:SQLALTERTABLEEMP1MODIFYdnamevarchar2(20)default‘Admin’;2/19/20138UsingAlterTableStatementModifyingaColumnSyntax:SQLALTERTABLEEMP1DROPCOLUMNdname;DROPINGATableSQLDROPTABLEemp1;2/19/20139ChangingNameOfAnObject:SQLTRUNCATINGATable:2/19/201310AddingCOMMENTSToATable:SQLCOMMENTONTABLEempIS‘Employeesinformation’;SQLCOMMENTONCOLUMNemp.mgrIS‘EmployeesManagerID’DataDictionaryViews:2/19/201311DataDefinitionLanguageViewingInfofromDictionaryTablesSQLSELECT*FROMUSER_COL_COMMENTSWHERETABLE_NAME=‘EMP1’;DATAMANIPULATIONLANGUAGE2/19/201312DMLDMLInsertingNewRecordsIntoATable2/19/201313DMLInsertingNewRecordsIntoATableSQLINSERTINTOdeptVALUES(50,’EXECUTIVE’,STERLING’);DMLInsertingNULLvaluesSQLINSERTINTOEMP(empno,ename,job,hiredate,comm)VALUES(1234,SYAM’,’MANAGER’,sysdate,NULL);2/19/201314DMLUsingScript:SQLINSERTINTOEMP(empno,ename,job)VALUES(&empno,’&ENAME’,’&JOb’);DMLCopyingrowsfromanothertable:SQLINSERTINTOEMP1(empno,ename,job,sal)SELECTempno,ename,job,salFROMempWHEREjob=‘MANAGER’;2/19/201315DMLChangingdatainaTable;DMLChangingdatainaTable;SQLUPDATEempSETename=‘STEVE’WHEREempno=7654;2/19/201316DMLChangingdatainaTable;SQLUPDATEempSETjob=(SELECTjobFROMempWHEREename=‘STEVE’),sal=(SELECTsalFROMempWHEREename=‘STEVE’),WHEREename=‘SCOTT’;DMLDeletingRecordsFromATable;2/19/201317DMLDeletingRecordsFromATable;SQLDELETEFROMEMPWHEREempno=7654;SQLDELETEDEPT;DATABASETRANSACTIONS2/19/201318TCLTransactionsTCLAdvantagesOfCOMMIT&ROLLBACK2/19/201319TCLControllingTransactionsTCLControllingTransactions2/19/201320TCLImplicitTransactionProcessing:TCLStateOfDataBeforeCommitOrRollback;2/19/201321TCLStateOfDataAfterCommit;TCLStateOfDataAfterRollback;2/19/201322TCLStatementLevelRollback;TCLReadConsistency:2/19/201323DATACONTROLLANGUAGEOBJECTPRIVILEGES:2/19/201324OBJECTPRIVILEGES:GrantingSelectPrivilegeonEmptoSCOTTuserSQLGRANTSELECTONemptoSCOTT;GrantingUpdatePrivilegeonEmptouserSCOTT&STEVESQLGRANTUPDATEONemptoSCOTT,STEVE;OBJECTPRIVILEGES:GrantingPrivilegestoUpdatespecificcolumnstoUsersSQLGRANTUPDATE(sal,job)ONempTOSCOTT,STEVE;GrantingAllPrivilegesonEmptouserSCOTTSQLGRANTALLONemptoSCOTT;2/19/201325UsingWithGrantandPublicKeywordsGrantingaUserAuthorityToPassOnPrivileges:SQLGRANTSELECT,INSERTONdeptTOSCOTTWITHGRANTOPTION;GrantingAllUsersintheDatabasetoaccessDatafromDeptTableSQLGRANTSELECTONdepttoPUBLIC;ConfirmingPrivilegesGranted2/19/201326RevokingPrivilegesGrantedOBJECTPRIVILEGES:RevokingSelectPrivilegeonEmpFromSCOTTuserSQLREVOKESELECTONempFORMSCOTT;RevokingUpdatePrivilegeonEmpFromSCOTT&STEVESQLREVOKEUPDATEONempFROMSCOTT,STEVE;2/19/201327CONSTRAINTSCONSTRAINTS2/19/201328CONSTRAINTSSyntaxCONSTRAINTSSQLCREATEtablestudent(snonumber(3),snamevarchar2(20)constraintstd_sname_uunique,smarksnumber(3))2/19/201329CONSTRAINTSAtColumn&TableLevel:CONSTRAINTSAtColumn&TableLevel:SQLCREATEtablestudent(snonumber(3)notnull,snamevarchar2(20)constraintstd_sname_uunique,smarksnumber(3),sagenumber(3)check(sage120),constraintstd_smarks_ccheck(smarks=600));2/19/201330UNIQUECONSTRAINTPRIMARYKEYCONSTRAINT2/19/201331FOREIGNKEYCONSTRAINTFOREIGNKEYCONSTRAINT2/19/201332ADDACONSTRAINTDROPINGACONSTRAINT2/19/201333DISABLINGACONSTRAINTENABLINGACONSTRAINT2/19/201334VIEWINGCONSTRAINTSVIEWINGCOLUMNSASSOCIATEDWITHCONSTRAINTS2/19/201335Session1Joins.SQL:1999CompliantJoinsSession2SubQueriesProducingReadableOutputWithSQL*Plus.JOINS2/19/201336TYPESOFJOINSTYPESOFJOINSSQLCOMPLIANT1999JOINS:2/19/201337JOINSCARTESIANPRODUCTJOINSCARTESIANPRODUCTSQLSELECTename,dnameFROMemp,dept;2/19/201338JOINSEQUIJOINSQLSELECTename,dnameFROMemp,deptWHEREemp.deptno=dept.deptno;JOINSEQUIJOINSQLSELECTename,dname,emp.deptnoFROMemp,deptWHEREemp.deptno=dept.deptno;2/19/201339JOINSEQUIJOINSQLSELECTemp.ename,dept.dname,emp.deptnoFROMemp,deptWHEREemp.deptno=dept.deptno;JOINSEQUIJOINusingtablealiases:SQLSELECTe.ename,d.dname,e.deptnoFROMempe,deptdWHEREe.deptno=d.deptno;2/19/201340JOINSNON-EQUIJOINSQLSELECTe.ename,e.sal,e.job,s.gradeFROMempe,salgradesWHEREsalbetweenlosalandhisal;JOINSJOININGMORETHANTWOTABLES:SQLSELECTe.ename,e.sal,d.dname,s.gradeFROMempe,s