+ All Categories
Home > Documents > SYBCA 201 UNIT 1 Unprotected

SYBCA 201 UNIT 1 Unprotected

Date post: 09-Apr-2018
Category:
Upload: onlytej
View: 216 times
Download: 0 times
Share this document with a friend

of 21

Transcript
  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    1/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    EMP_NO

    NAMESKILL123456 POSITION_NO

    Faculty Name : Mehul PatelClass : SYBCASubject : RDBMS (BCA-201)Topics : Unit I

    > WHAT IS DATABASEA database can be defined as a collection of coherent, meaningful data. The phrasecollection of coherent data needs to have a point of reference to be understood. Asimple point of reference would be the example of a postal address, this wouldgenerally contain:

    o A building name,o A flat number in the buildingo A road nameo An area nameo A state nameo A pincodeo A country name (This is optional, but necessary if the letter is destined to a

    foreign country)

    To project on this further, multiple addresses kept together in one place, such as anaddress book, could be termed as a coherent collection of data. Thus the address bookis a database and the postal addresses in the book, is the data that fills the database .

    > WHAT IS DATABASE MANAGEMENT SYSTEMS (DBMS)To be able to successfully design and maintain databases we have to do the following:

    1.Identify which part of the world' s data is of interest to us2.Identify what specific objects in that part of the world's data are of interest0.Identify a relationship between the objects

    Hence, the objects, there attributes and the relationship between them (that are of interest to us) are stored in the database that is designed, built and populated withdata for a specific purpose.

    Software houses took up the cha1lenge of designing a system that would help inmanaging data in such a database. These systems were called Database ManagementSystems (DBMS). DBMS is a system that allows inserting, updating, deleting andprocessing of data. Some of the DBMS developed by software houses were Oracle,Ingress, Sybase, Dbase 3+, Fox base, FoxPro, MS Access, Database, Data flex,Advanced Revelation, and so on.

    > ADVANTAGES OF DBMS:-

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    2/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21123457

    JONBUSBOY123458DONBELLBOY123459PAMHOSTESS

    WAITER323BUSBOY324BELLBOY325HOSTESS

    1. The amount of data redundancy in stored data can be reduced.2. No more data inconsistencies.3. Stored data can be shared by a single or multiple users .4. Standards can be set and followed .

    5. Data integrity can be maintained. Data integrity refers to the problem of ensuring that database contains only accurate data.

    6. Security of data can be simply implemented.7. Data independence can be achieved, i.e. data and programs that manipulate the

    data are two different entities.

    DISADVANTAGE OF DBMS:-

    1.Cost of Hardware / Software and Migration.2.Problems associated with centralization.3.Complexity of Backup and Recovery.

    Relational Data Model

    The relational data model has emerged from the research, development, test andtrial stages as a commercial product. Software systems using this approach areavailable for all size of computer system. This model has the advantage of beingsimple in principle; users can express their queries in a powerful query language.

    In this model, the relation is the only construct required to represent theassociation among the attributes of an entity as well as the relationship amongdifferent entities. One of the main reason for introducing this model was to increasethe productivity of the application programmer by eliminating the need to change

    application programs when a change is made to the database. Users need not knowthe exact physical structure to use the database and are protected from anychanges made to these structures. They are however, still required to know thedata has been partitioned into the various relations.

    EMPLOYEE POSITION

    The relation is the only data structure used in the relational data model to representboth entities and the relationship between them. A relation may be visualized as anamed table. Above figure shows two relations employee and position using tabularstructure. Each column of the table corresponds to an attribute of the relation andis named.

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    3/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > WHAT IS A RELATIONAL DATABASE MANAGEMENT SYSTEM(RDBMS)

    A Relational Database Management System (RDBMS) is a database managementsystem (DBMS) that is based on the relational model as introduced by Dr. Edgar F.

    Codd. Strictly speaking it should also satisfy Codd's 12 rules, but in practice there is noDBMS that satisfies all these rules. In fact, most successful DBMS that are consideredto be relational violate the relational model in several important ways, including theStructured Query Language (SQL). However, most database practitioners andresearchers use the term in a loose way such that most databases that support SQLare included.

    Relational Database Management Systems (RDBMS) stores data in the form of relatedtables. RDBMS are powerful because they require few assumptions about how data isrelated or how it will be extracted from the database. As a result, the same databasecan be viewed in many different ways.

    An important feature of relational systems is that a single database can be spreadacross several tables. This differs from flat-file databases, in which each database isself-contained in a single table.

    Today, popular commercial RDBMS for large databases include Oracle, Microsoft SQLServer, Sybase SQL Server, and IBM's DB2. The most commonly used free RDBMS areMySQL, PostgreSQL.

    > Dr. E. F. Codd's Rules for RDBMSDr. E. F. Codd is an IBM researcher who first developed the relational data model in1970. In 1985, Dr. Codd published a list of 12 rules that define an ideal relational

    database and has provided a guideline for the design of all relational databasesystems.

    Today, the rules are not talked about as much but remain a goal for relationaldatabase design .

    Rule 1: The Information RuleAll data should be presented in table form

    Rule 2: Guaranteed Access RuleAll data should be accessible without ambiguity. This can be accomplished

    through a combination of the table name, primary key, and column name

    Rule 3: Systematic Treatment of Null ValuesA field should be allowed to remain empty. This involves the support of a nullvalue, which is distinct from an empty string or a number with a value of zero.Of course, this can't apply to primary keys. In addition, most databaseimplementations support the concept of a not-null field constraint that preventsnull values in a specific table column

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    4/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    Rule 4: Dynamic On-Line Catalog based on the Relational ModelA relational database must provide access to its structure through the sametools that are used to access the data. This is usually accomplished by storingthe structure definition within special system tables

    Rule 5: Comprehensive Data Sublanguage Rule

    The database must support at least one clearly defined language that includesfunctionality for data definition, data manipulation, data integrity, and databasetransaction control. All commercial relational databases use forms of standardSQL (i.e. Structured Query Language) as their supported comprehensivelanguage

    Rule 6: View Updating RuleData can be presented in different logical combinations called views. Each viewshould support the same full range of data manipulation that has direct accessto a table available. In practice, providing update and delete access to logicalviews is difficult and is not fully supported by any current database

    Rule 7: High-Level Insert, Update, and DeleteData can be retrieved from a relational database in sets constructed of datafrom multiple rows and/or multiple tables. This rule states that insert, update,and delete operations should be supported for any retrievable set rather than

    just for a single row in a single table.Rule 8: Physical Data Independence

    The user is isolated from the physical method of storing and retrievinginformation from the database. Changes can be made to the underlyingarchitecture (hardware, disk storage methods) without affecting how the useraccesses it.

    Rule 9: Logical Data IndependenceHow data is viewed should not be changed when the logical structure (table'sstructure) of the database changes. This rule is particularly difficult to satisfy.Most databases rely on strong ties between the data viewed and the actualstructure of the underlying tables.

    Rule 10: Integrity IndependenceThe database language (like SQL) should support constraints on user input thatmaintain database integrity. This rule is not fully implemented by most majorvendors. At a minimum, all databases do preserve two constraints through SQL.No component of a primary key can have a null value. If a foreign key is definedin one table, any value in it must exist as a primary key in another table .

    Rule 11: Distribution IndependenceA user should be totally unaware of whether or not the database is distributed

    (whether parts of the database exist in multiple locations). A variety reasonsmake this rule difficult to implement .

    Rule 12: Non subversion RuleThere should be no way to modify the database structure other than through themultiple row database language (like SQL). Most databases today supportadministrative tools that allow some direct manipulation of the data structure .

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    5/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > DBMS V/S RDBMSDBMS RDBMS

    In DBMS relationship between two tablesor files are maintained programmatically

    In RDBMS relationship between two tablesor files can

    be specified at the time of table creationDBMS does not support Client/ServerArchitecture

    Most of the RDBMS supports Client/ServerArchitecture

    DBMS does not supports Distributeddatabases

    Most of the RDBMS supports Distributeddatabases

    In DBMS there is no security of data In RDBMS there are multiple levels of security1.Logging in at O/S level2.Command level

    (i.e. at RDBMS level)3.Object Level

    Each table is given an extension in DBMS Many tables are grouped in one databasein RDBMS

    DBMS may satisfy less than 7 to 8 rules of Dr. E F Codd

    RDBMS usually satisfy more than 7 to 8rules of Dr. E F Codd

    > Naming ConventionsDBMS RDBMS

    Field Column, AttributesRecord Row, Tuple, EntityFile Table, Relation, Entity Class

    Many of the databases will be small, with one or two tables. But as the databasesbecome braver, tackling, bigger projects, it will be noticed that the design of the tablesis proving problematic. The SQL written starts to become unmanageable and dataanomalies start to creep in. This means it is time to learn about databasenormalization, or the optimization of tables.

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    6/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > NORMALIZATION

    Normalization is a process that helps analysts or database designers to design tablestructures for an application. The focus of normalization is to attempt to reduceredundant table data to the very minimum.Through the normalization process, the collection of data in a single table is replaced,by the same data being distributed over multiple tables with a specific relationshipbeing setup between the tables. By this process RDBMS schema designers try theirbest to reduce table data to the very minimum.

    Normalization is carried out for the following reasons:1.To structure the data between tables so that data maintenance is simplified2.To allow data retrieval at optimal speed3.To simplify data maintenance through updates, inserts and deletes4.To reduce the need to restructure tables as new application requirements arise5.To improve the quality of design for an application by rationalization of table data

    Normalization is a technique that:1. Decomposes data into two-dimensional tables2. Eliminates any relationships in which table data does fully depend upon the primary

    key of a record3. Eliminates any relationship that contains transitive dependencies

    A description of the three forms of Normalization is as mentioned below.

    > First Normal FormWhen a table is decomposed into two-dimensional tables with all repeating groups of data eliminated, the table data is said to be in its first normal form.

    The repetitive portion of data belonging to the record is termed as repeating groups.To understand the application of normalization to table data the following tablestructure will be taken as an example :

    Table: EmpProField Key TypeProject Number --Project Name --Employee Number -- 1-nEmployee Name -- 1-nRate Category -- 1-n

    Hurly Rate -- 1-n

    1-n indicates that there are many occurrences of this field - it is a repeating group.

    Data held in the above table structure

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    7/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    Table: EmpProj

    ProjectNumber

    ProjectName

    EmployeeNumber

    EmployeeName

    RateCategory

    HourlyRate

    P001 My SQL & Linux E001 Sharanam A 7000P001 My SL & Linux E002 Vaishali B 6500

    P001 My SQL & Linux E006 Hansel C 4500P002 Office & Linux E001 Sharanam A 7000P002 Office & Linux E007 Chhaya B 4000

    In the above data there are a few problems:The Project Name in the second record is misspelled. This can be solved, byremoving duplicates. Do this using normalizationData is repeated and thus occupies more space

    A table is in 1st normal form if:There are no repeating groupsAll the key attributes are definedAll attributes are dependent on a primary key

    So far there are no keys, and there are repeating groups. So remove the repeatinggroups, and define the primary key.

    To convert a table to its First Normal Form:1. The un-normalized data in the first table is the entire table2. A key that will uniquely identify each record should be assigned to the table. This

    key has to be unique because it should be capable of identifying any specific rowfrom the table for extracting information for use. This key is called the table'sprimary key.

    This table is now in 1st normal form.

    Field KeyProject Number Primary KeyProject Name --Employee Number Primary KeyEmployee Name --Rate Category --Hurly Rate --

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    8/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    FieldKeyProject NumberPrimary KeyEmployee NumberPrimary Key

    Table: Emp

    > Second Normal FormA table is said to be in its second normal form when each record in the table is in thefirst normal form and each column in the record is fully dependent on its primary key.

    A table is in 2nd normal form if:It's in 1st normal formIt includes no partial dependencies (where an attribute is dependent ononly a part of a primary key)

    The steps to convert a table to its Second Normal Form:1.Find and remove fields that are related to the only part of the key2.Group the removed items in another table3.Assign the new table with the key i.e. part of a whole composite key

    Going through all the fields reveals the following:Project name is only dependent on Project number

    Employee name, Rate category and Hourly rate are dependent only on Employeenumber

    To convert the table into the second normal form remove and place these fields in aseparate table, with the key being that part of the original key they are dependent on.

    This leads to the following 3 tables:

    Table: EmpProj

    Table: ProjField KeyProject Number Primary KeyProject Name --

    Field KeyEmployee Number Primary KeyEmployee Name --Rate Category --

    Hurly Rate --

    The table is now in 2nd normal form, but not yet in its 3rd normal form

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    9/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    Table: EmpProj

    Table: Proj

    : Emp: Rate

    FieldKey

    FieldEmployee NumberEmployee NameRate Category

    KeyPrimary Key

    > Third Normal FormTable data is said to be in third normal format when all transitive dependencies areremoved from this data".

    The table is in 3rd normal form if:

    It's in 2nd normal formIt contains no transitive dependencies (where a non-key attribute isdependent on another non-key attribute)

    A general case of transitive dependencies is as follows:A, B, C are three columns in table.If C is related to B If B isrelated to A Then C is indirectlyrelated to AThis is when transitive dependency exists.

    To convert such data to its third normal form remove this transitive dependency by

    splitting each relation in two separate relations. This means that data in columns A, B,C must be placed in three separate tables, which are linked using a foreign key

    Going through all the fields reveals the following:Employee table is the only one with more than one non-key attributeEmployee name is not dependent on either Rate category or Hourly rateHourly rate is dependent on Rate category

    To convert the table into the third normal form remove and place these fields in aseparate table, with the attribute it was dependent on as key, as follows:

    This leads to the following 4 tables:

    Field KeyProject Number Primary KeyEmployee Number Primary Key

    Field KeyProject Number Primary KeyProject Name --

    Rate Category --Hurly Rate --

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    10/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel 10/21

    These tables are all now in their 3rd normal form, and ready to be implemented. Thereare other normal forms such as Boyce-Codd normal form (BCNF), 4th and 5th normalform, but these are very rarely used for business applications. In most cases, tablesthat are in there 3rd normal form are already conforming to these types of tableformats anyway.

    > Circumstances under which Normalization can be avoidedThere are situations when normalization can be avoided. This can be seen in thefollowing table structure:

    Table: CustomerField KeyCustomer Number Primary KeyCustomer Name --Address --Pincode --City --

    Going through all the fields reveals the following:No repeating groups exists

    A primary key is defined

    This proves that it is at least in 1st normal formThere is only one key so partial dependencies do not exists

    This proves that it is at least in 2nd normal formThere are transitive dependencies

    It seems that like City might be determined by Pincode, which' is usually the case inmost parts of the world, but there is no need to remove City, and place it in a separatetable, with Pincode as the key.

    Although this table is not technically in its 3rd normal format, removing thisinformation is not worth it. Creating more tables increases the load slightly, slowingprocessing down. This is often counteracted by the reduction in table sizes, andredundant data. But in this case, where the City would almost always be referenced aspart of the address, it isn't worth it. Normalization is just a helpful process that usuallyresults in the most efficient table structure, and not a rule for database design.

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    11/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel 11/21

    > INTRODUCTION TO ORACLE

    Way back in June 1970, Dr E. F. Codd published a paper entitled A Relational Model of Data for Large Shared Data Banks. This relational model, sponsored by IBM, thencame to be accepted as the definitive model for RDBMS. The language developed byIBM to manipulate the data stored within Codd's model was originally called StructuredEnglish Query Language (SEQUEL) with the word English later being dropped in favorStructured Query Language (SQL).

    In 1979 a company called, Relational Software, Inc. released the first commerciallyavailable implementation of SQL. Relational Software later came to be known as OracleCorporation. Oracle Corporation is a company that produces the most widely used,Server based, Multi-user RDBMS named Oracle.

    INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)Structured Query Language (SQL) is a language that provides an interface to relationaldatabase systems. SQL was developed by IBM in the 1970s for use in System R, and isa de facto standard, as well as an ISO and ANSI standard. SQL is often pronouncedSEQUEL.

    In common usage SQL also encompasses DML (Data Manipulation Language), forInserts, Updates, Deletes and DDL (Data Definition Language), used for creating and111odifying tables and other database structures.

    > What is SQL?SQL (Structural Query Language) is a set of commands that lets you access arelational database. SQL is a standard interface for many relational databases. It has asimple command structure for data definition, access, and manipulation. SQL is set-

    oriented and non-procedural. When you use SQL you specify what to be done, not howto do it.

    > Features of SQL:1. SQL can be used by a range of users, including those with little or no programming

    experience.2. It is a non-procedural language.3. It reduces the amount of time required for creating and maintaining systems.4. It is an English-like language.

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    12/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel 12/21

    > Rules for SQL1. SQL starts with a verb {i.e. a SQL action word).

    Example: SELECT statements. This verb may have additional adjectives.Example: SELECT ... FROM

    2. Each verb is followed by number of clauses.Example: FROM, WHERE, HAVING

    3. A space separates clauses. Example: DROP TABLE EMP;4. A comma (,) separates parameters (without a clause)5. A ';' is used to end SQL statements6. Statements may be split across lines but keywords may not

    7. Lexical units such as identifiers, operator names, literals are separated by one ormore spaces or other delimiters that will not be confused with the lexical unit

    8. Reserved words cannot be used as identifiers unless enclosed with double quotes.Reserved words are: ALL, DROP, USER, ORDER, DELETE, SELECT, INITIAL,ROWLABEL, VIEW, EXISTS, UNIUE, INTEGER, AS, ASC, INTO, ALTER, ROWID,INSERT, VALUES, VARCHAR2 etc...

    9. Identifiers can contain up to 30 characters and must start with an alphabeticcharacter

    0. Character and date literals must be enclosed within single quotes0. Numeric literals can be represented by simple values such as 0.32, -34, 01991,

    and so on,Scientific notation as 2E5 meaning 2x1O to the power of 5 = 200,000.

    1. Comments may be enclosed between /* and */ symbols and may be multi line.Single line comments may be prefixed with a- symbol

    > SQL DelimitersDelimiters are symbols or compound symbols, which have a special meaning within

    SQL and PL/SQL statements,

    + Addition Quote Identifier- Subtraction : Host Variable* Multiplication ** Exponential

    / Division != ^= Relational=>< Relational = Relational() Expression or list := Assignment; Terminator => Association% Attribute indicator || Concatenation, Item Separator

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    13/21

    ----

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > Components of SQL1.DDL (Data Definition Language)

    It is a set of SQL commands used to create, modify and delete databasestructure but not data. These commands are normally not used by a generaluser, who should be accessing the database via an application. They arenormally used by the DBA to a limited extent, a database designer or applicationdeveloper. These statements are immediate i.e. they are not susceptible toROLLBACK commands. It should also be noted that if several DML statementsfor example update's are executed then issuing any DDL command wouldCOMMIT all the updates as every DDL c6mmand implicitly issues a COMMITcommand to the database. Anybody using DDL must have the CREA TE objectprivilege and a Table space area in which to create objects.

    2.DML (Data Manipulation LanguageIt is the area of SQL that allows changing data within the Database.

    3.DCL (Data Control Language)It is the component of SQL statement that control access to data and to the

    database. Occasionally DCL statements are grouped with DML statements.4.DQL (Data Query Language)

    It is the component of SQL statement that allows getting data from the databaseand imposing ordering upon it. In includes the SELECT statement. Thiscommand is heart of SQL. It allows getting the data out of the database performoperations with it. When SELECT is fired against a table or tables the result iscompiled into a further temporary table, which displayed or perhaps received bythe program i.e. a front-end.

    > Examples of DDL, DML and DCL commands

    DDL: Data Definition Language StatementsExamples:

    CREATE - To create objects in the databaseALTER - alters the structure of the databaseDROP - Delete objects from the database

    TRUNCATE - Remove all records from a table, including all spaces allocated for therecords are removed

    COMMENT - Add comments to the data dictionaryGRANT - Gives user's access privileges to databaseREVOKE - Withdraw access privileges given with the GRANT command

    DML: Data Manipulation Language statements

    Examples:INSERT - Insert data into a tableUPDATE - Updates existing data within a tableDELETE - Deletes all records from a table, the space for the records remainCALL - Call a PL/SQL or Java subprogramEXPLAINS PLAN - Explain access path to dataLOCK - TABLE Control concurrency

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    14/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    DCL: Data Control Language statementsExamples:

    COMMIT - Save work doneSAVEPOINT - Identify a point in a transaction to which you can later roll backROLLBACK - Restore database to original since the last COMMITSET TRANSACTION - Change transaction options like what rollback segment to useGRANT / REVOKE - Grant or take back permissions to or from the oracle users

    DQL: Data Query Language statementExamples:

    SELECT - Retrieve data from the a database

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    15/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > DATATYPE(S):

    1. Character Data typesCharacter data types are used to manipulate words and free-form text. These

    data types are used to store character (alphanumeric) data in the database or nationalcharacter set. They are less restrictive than other data types and consequently have

    fewer properties.These data types are used for character data:

    CHARVARCHARVARCHAR2

    CHAR Data typeThe CHAR data type specifies a fixed length character string. When you create a

    table with a CHAR column, you supply the column length in bytes. Oracle subsequentlyensures that all values stored in that column have this length. If you insert a value

    that is shorter than the column length, Oracle blank-pads the value to column length.If you try to insert a value that is too long for the column, Oracle returns an error.The default length for a CHAR column is 1 character and the maximum allowed is

    2000 characters. A zero-length string can be inserted into a CHAR column, but thecolumn is blank-padded to 1 character when used in comparisons.

    VARCHAR2 DatatypeThe VARCHAR2 datatype specifies a variable length character string. When you

    create a VARCHAR2 column, you can supply the maximum number of bytes of datathat it can hold. Oracle subsequently stores each value in the column exactly as youspecify it, provided it does not exceed the column's maximum length. This maximummust be at least 1 byte, although the actual length of the string stored is permitted tobe zero. If you try to insert a value that exceeds the specified length, Oracle returns anerror.

    You must specify a maximum length for a VARCHAR2 column. The maximum lengthof VARCHAR2 data is 4000 bytes .

    VARCHAR DatatypeThe VARCHAR datatype is currently synonymous with the VARCHAR2 datatype.

    It is recommended that you use VARCHAR2 rather than VARCHAR. In a future versionof Oracle, VARCHAR might be a separate datatype used for variable length characterstrings compared with different comparison semantics .

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    16/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    2. NUMBER DatatypeThe NUMBER datatype is used to store zero, positive and negative fixed and

    floating point numbers with magnitudes between 1.0 x 10-130 and 9.9...9 x 10 125 (38 9sfollowed by 88 0s) with 38 digits of precision. If you specify an arithmetic expressionwhose value has a magnitude greater than or equal to 1.0 x 10 126 , Oracle returns anerror.

    You can specify a fixed-point number using the following form:NUMBER (p,s)Where,

    p is the precision , or the total number of digits. Oracle guarantees the portability of numbers with precision ranging from 1 to 38.

    s is the scale, or the number of digits to the right of the decimal point. The scalecan range from -84 to 127.The following examples show how Oracle stores data using different precisions andscales.

    Actual Data Specified As Stored As

    7456123 .89 NUMBER 7456123 .897456123 .89 NUMBER(9) 7456124

    7456123 .89 NUMBER(9,2) 7456123 .89

    7456123 .89 NUMBER(9,1) 7456123 .9

    7456123 .8 NUMBER(6) exceeds precision

    7456123 .8 NUMBER(15,1) 7456123 .8

    7456123 .89 NUMBER(7,-2) 7456100

    7456123 .89 NUMBER(-7,2) exceeds precision

    You can specify a scale that is greater than precision, although it is uncommon.In this case, the precision specifies the maximum number of digits to the right of thedecimal point. As with all number datatypes, if the value exceeds the precision, Oraclereturns an error message. If the value exceeds the scale, Oracle rounds the value. Forexample, a column defined as NUMBER (4,5) requires a zero for the first digit after thedecimal point and rounds all values past the fifth digit after the decimal point. Thefollowing examples show the effects of a scale greater than precision:

    Actual Data Specified As Stored As

    .01234 NUMBER (4,5) .01234

    .00012 NUMBER (4,5) .00012

    .000127 NUMBER (4,5) .00013

    .0000012 NUMBER (2,7) .0000012

    .00000123 NUMBER (2,7) .0000012

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    17/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    3. LONG DatatypeLONG columns store variable length character strings containing up to 2

    gigabytes, or 2 31 -1 bytes. LONG columns have many of the characteristics of VARCHAR2 columns. You can use LONG columns to store long text strings. Oracle uses

    LONG columns in the data dictionary to store the text of view definitions. The length of LONG values may also be limited by the memory available on your computer.The use of LONG values is subject to some restrictions:

    > A table cannot contain more than one LONG column.> LONG columns cannot appear in integrity constraints (except for NULL and NOT

    NULL constraints).> LONG columns cannot be indexed.> A stored function cannot return a LONG value.> Within a single SQL statement, all LONG columns, updated tables, and locked

    tables must be located on the same database.

    4. DATE DatatypeThe DATE datatype is used to store date and time information. Although date

    and time information can be represented in both CHAR and NUMBER datatypes, theDATE datatype has special associated properties.For each DATE value the following information is stored:

    centuryyearmonthdayhour

    minutesecond

    5. RAW and LONG RAW DatatypesThe RAW and LONG RAW datatypes are used for data that is not to be interpreted

    (not converted when moving data between different systems) by Oracle. These datatypes are intended for binary data or byte strings. For example, LONG RAW can beused to store graphics, sound, documents, or arrays of binary data; the interpretationis dependent on the use.

    LONG RAW data cannot be indexed, but RAW data can be indexed.

    6. Large Object (LOB) Data typesInternal LOB data types, BLOB, CLOB, NCLOB, and external data type BFILE, canstore large and unstructured data such as text, image, video, and spatial data, up tofour gigabytes in size.

    You can define one or more LOB data type columns in a table .

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    18/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    7. ROWIDFor each row in the database, the ROWID pseudo column returns a row's address.

    Usually, a ROWID value uniquely identifies a row in the database. However, rows indifferent tables that are stored together in the same cluster can have the sameROWID.

    Values of the ROWID pseudo column have the data type ROWID.

    ROWID values have several important uses:They are the fastest way to access a single row.They can show you how a table's rows are stored.They are unique identifiers for rows in a table.

    You should not use ROWID as a table's primary key. If you delete and reinsert arow with the Import and Export utilities, for example, its ROWID may change. If youdelete a row, Oracle may reassign its ROWID to a new row inserted later.

    Although you can use the ROWID pseudo column in the SELECT and WHERE clausesof a query, these pseudo column values are not actually stored in the database. Youcannot insert, update, or delete a value of the ROWID pseudo column.

    Example: Select ROWID from EPM;

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    19/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > CREATE TABLETYPE: DDLSYNTAX:

    CREATE TABLE tablename(columnname datatype(size), columnname datatype(size)....);

    Whenever user creates table, the table name must be a legal SQL name and itmust not conflict with the name of any of your existing tables.e.g.CREATE TABLE stud(s_no NUMBER(3), s_name VARCHAR2(15), address VARCHAR2(20) );

    Creating a table from previously created table.SYNTAX:CREATE TABLE tablename1 (columnanme, columnname.....) AS SELECTcolumnname,columnname..... FROM tablename2[WHERE ]Note: If the tablename2 is having records in it then the target table

    tablename1 is populated with records well.e.g CREATE TABLE stud1 AS SELECT * FROM STUD;Create duplicate table with empty:CREATE TABLE AS SELECT * FROM WHERE1=2

    > DROP TABLETYPE: DDLSYNTAX: DROP TABLE tablename;Removing the table and all its data and constraints from the database.Example: DROP TABLE stud;

    > INSERTION OF DATA INTO TABLES

    TYPE: DMLPurpose: To add rows/records to a table or a views base table.SYNTAX: INSERT INTO [columnname, ...... ]VALUES (, . . .);Bind variables:1.&variable_ name

    It will not preserve value to a variable. Once the value is transferred into aspecific column each time it will ask the user to input users to input value.INSERT INTO [ ,.....] VALUES (&S_NO,....);

    2.&&variable_nameIt will preserve value to a variable. It is used for define variable first time.It will not ask user second time and previous values will automatically beenassigned to the specific field .INSERT INTO [ ,.....] VALUES(&&S_NO,&&SNAME,....);

    Inserting data into a table from another table:INSERT INTO tablename SELECT columnname,columnname FROMtablename [ WHERE ];

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    20/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    > UPDATING A CONTENTS OF A TABLE:

    TYPE: DMLSYNTAX:UPDATE

    SET columnname = , columnname =[ WHERE ];Changing the existing values in a table or in a views base table.

    > DELETION OPERATIONS:TYPE: DMLSYNTAX:

    DELETE [FROM] [WHERE ];To remove row(s) from table:

    DELETE FROM ;Will delete all the records from a table name specifiedDELETE FROM WHERE Will delete all therecords, which satisfies the condition specified after where.

    > TRUNCATETYPE: DMLSYNTAX: TRUNCATE TABLE ;Will delete all the records from a table and records cannot be ROLLBACK.

    > RENAMETYPE: DDLSYNTAX: RENAME TO ;User can rename a table.

    > SELECT COMMAND:TYPE: DMLSYNTAX:

    SELECT * FROM tab ;Will display the information of all the tables, views in the current database.

    SELECT * FROM tablename ;Will display all the records from a table with all the fields.

    SELECT columnname, columnname FROM tablename;Will display all the records with specific fields that user has specified withSELECT command.

    SELECT * FROM WHERE ;Will display all the records with given condition specified after WHERE willbecome true.

    SELECT DISTINCT columname FROM tablename ;Will eliminate the duplicate records for column specified after DISTINCT

    SELECT columnname, columnname FROM ORDER BY columnname , columnname ;

  • 8/8/2019 SYBCA 201 UNIT 1 Unprotected

    21/21

    RDBMS (BCA-201) Class: SYBCA Unit - IMehul Patel /21

    Sorting of data in a table.

    SELECT columnname, columnname FROM ORDER BY [ASCE | DESC];Here specifies that the field number that means user can specify fieldnumber instead of specifying the columnname.ASCE means sort the records in an ascending order.

    DESC means sort the records in a descending order.> VIEWING THE TABLE STRUCTURE:

    SYNTAX:DESCRIBE

    ORDESC

    > MODIFYING THE STRUCTURE OF TABLE:TYPE: DDLADDING NEW COLUMNS:SYNTAX:

    ALTER TABLE ADD(newcolumnname datatype(size), newcolumnname datatype(size));MODIFYING EXISTING COLUMNS:

    ALTER TABLE MODIFY(Columnname newdatatype (size));

    DELETING COLUMNSALTER TABLE DROP COLUMN ;

    Restrictions on the ALTER table:User cannot change the column name

    User cannot decrease the size of column if record(s) there in the table forthat column.Earlier versions do not support the deletion of column(s ).

    > SPOOLTo store the results of a query in a file as well as print and display on the screenusing SPOOL command:Syntax: SPOOL

    After given the spool with file name that tells SQL to store all theinformation that is displayed on the screen after SPOOL command has beenentered, into the specified file. The default file extension is .LST unless userspecifies the specific extension.

    SQL will continue to spool information to the file until you turn spoolingoff.SPOOL OFF: -) Will stop spooling data to a file.

    SPOOL OUT: -) This command will stop spooling and will also copy the spool filescontents to a default printer .


Recommended