Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
27 views
18 pages
SQL
In this pdf there are lot of SQL command that will help you
Uploaded by
Ashok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Download as pdf
Save SQL For Later
Download
Save
Save SQL For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
27 views
18 pages
SQL
In this pdf there are lot of SQL command that will help you
Uploaded by
Ashok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Download as pdf
Save SQL For Later
Carousel Previous
Carousel Next
Save
Save SQL For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
Download as pdf
You are on page 1
/ 18
Search
Fullscreen
te © Thename must begin withan alphabet and may contain characters A-Z, i 0-9, _, $and #. The use of $ and # is discouraged * Oracle reserved words may not be used 4.3.2 Data Types When a table is created, the type of data that can appear in each column has to ‘ve specified. The data types are: © Character columns may contain a maximum of 240 characters * Date columns may contain valid dates from January 14712 BC to December 31, 4712 AD © Number columns may contain numeric data witha maximum precision of 40 digits, excluding decimal point and sign. The number column may contain decimal, integer and floating point data J * Long columns may contain character data upto 65,535 characters i + Rawcolumns may contain raw binary data, upto 240 bytes * Long Raw may contain binary data upto 65,535 bytes 4.4 What is SQL , SQL is a Non Procedural Language In the conventional programming languages, coding is essential to achieve a given task. In addition to specifying the task to be achieved, how to go about doing it also has to be specified. In SQL only the task that has to be achieved is _ specified. For example, to retrieve rows from the table simply use the Select statement. es t a n I ‘ , d A Data Sublanguage SQL does not support programming language constructs. Conditional state- _ Ments like If Then, While cannot be used in SQL. Nota Database Management System SQL is an important tool for communicating with the DBMS and supports database management statements. oe Introduction to SQL* PiusCan be embedded in programming languages SQL statements can be embedded in thi COBOL to facilitate database access. nO geneeuion gare Mh cy SQL is a language for communicating with the DBMS i e Itisan Interactive Query Language that allows users to use SQ, ' ments to retrieve data and display it on the screen. SQL is anim tool that allows adhoc queries on the database. Potty ¢ A Database Programming Language that allows programmer, embed SQL statements in third generation language programs toacs ‘ data from the database. . A Database Administration Language that defines the structure of, i database, controls the user access to data and also the level OF usy access. Client/Server Language that allows application programs on PCs con, nected via a LAN to communicate with the database servers using SQ - Applications using Client/Server Language make optimum use of te; PCs and Servers and also reduce traffic over the LAN. ' * Distributed Database Language is used when data is distributed ove many machines. The Distributed Database Management System use SQL to communicate with the distributed databases. uses SQL to communicate with DBMS ed in a network. ¢ Database Gateway Language from different vendors being us:— = -=—Te Report Writer acili ty Database to other computer 4.4.1 SQL Statements Every SQL statement begins with a verb. The verb specifies the action to be performed by the statement eg. Create, Insert, Delete, Select Update and Commit . WHERE FROM INTO SET GROUP BY ORDER BY HAVING q The verb is followed by one or more clauses. The clause specifies the data to be acted upon and also the details about the SQL statement eg. Where, From, Into, Set, Group By, Order By and Having. The clauses generally contain table names, column names, keywords, constants or expressions. The SQL statement terminates with a";" that indicates the end of the statement and starts execution. SQL statements and SQL*Plus commands are not case sensitive. 61 Introduction to SQL* PluseS ey) Session 9 Creating and Modifying Tables At the end of this session, you will be able to: Create new tables Insert rows into tables Modify table definitions Modify the rows Rename the tables Drop the tables from the Data Dictionary eee ee 9.1 Data Definition Language (DDL) The SQL data Definition Language consist of SQL Data Definition commands. The DDL has commands to create new tables, alter tables and drop tables. All the table definitions are stored in the Data Dictionary: 9.1.1 Creating @ Table Tables can only pe created by users who have been granted the special rights by the Database Administrator, DBA.A table can be created by using the CREATE statement. The syntax is: | access tablename (sizes CREATE TABLE (columnl datatyPe column2 datatyPe *ble can have a maximum AR, NUMBER and Dany Column names are unique to the table. A tal the tables. There are no Ty columns. The datatype ‘of columns include CH length of the column can be defined while create in the new table. 9.1.2 Create Tocreatea new table Student with columns Rol1No, Name, Batch Perc, the usage of the CREATE statement is: mt CREATE TABLE ' STUDENT (Rol1No NUMBER NOT NULL, Name CHAR (15) + Batch CHAR (3), Percent NUMBER) 7 The new table name is specified after the CREATE TABLE clause. The table is the data type and the width of the named STUDENT. The column names, columns must be specified and enclosed in paranthesis. The character columns, Name and Batch, have a width of 15 and 3 respectively. The length of the numericcolumns need notbe specified. Whena columnis defined as NOT NULL, the DBMS en sures that a null value will not be inserted in that column. 9.1.3 Modifying Tables ou to modify them. Tables Oncea table has been created, SQL*Plus allows y be modified in two ways (i) New columns can be added and (ii) The data typ of existing columns can be modified. The syntax of the statement toaddanew column is: ALTER TABLE tablename ADD (NewColumn1Name datatype (size), NewColumn2Name datatype (size)); Design & Implementation Taz of Oracle DBMS9.2.1 Inserting Tuples / a A table has to be created before inserting rows. The sy! le Tg statement is: INSERT INTO tablename e2, +s VALUES (ColumnValuel, Columnvalu . h row to be inserted. The values, arey ERT statemant is used for eac! s ‘ “4 ere every column in the table. The values to be inserted into columns my match the data type of column. Null values can be inserted in the column, if NOT NULL not specified ws; creating the tables. Char and date values to be enclosed in single quotes, 9.2.2 Insert Toadd rows of data to the Table Student, the usage of the INSERT Statemey is: INSERT INTO Student VALUES (01, ‘Manish Patel’, 16, 75, '12-Jul-91'); Data to be inserted into the char column, Name, and the date colum, JoinDate, are enclosed in quotes. There is data for every column of the table Incases where some portion of the data is not known, nulls have to be inserted, INSERT INTO Student VALUES (02, ‘Rajesh Pai’, 16, null, null); Notice that null values are entered without quotes. Semicolon starts execution of the INSERT statement. 9.2.3 Updating Tuples UPDATE tablename SET columnl = NewValuel, column2 = Newvalue2 WHERE condition; Dep ERma of Oracle DBMS 136co the WHERE clauseis used data in the rows that satisfy the WHERE condition When ated, data in the other rows are not modified. If WHERE is not used, data sf rows will be modified. A column value can be modified toa null value. jn! ample modify data in the existing row the usage is: pPDATE Student SET Percent =70 WHERE RollNo = 02; qhe above statement modifies the percentage of Rajesh Pai to 70. To ‘The WHERE clause is used to identify the specific row. Another solution to this ry is to identify the row by the student name. If there are one or more rows jnthe Student table where Rol 1No = 2, then the Percent column in all the rows will be modified. COLUMN Rol1No FORMAT A6; SELECT * FROM Student; RollNo Name Batch Percent JoinDate 01 Manish Patel 16 75 12-Jul-91 02 Rajesh Pai 15 70 null . 92.4 Deleting Tuples Todelete existing rows in the table, the DELETE command is used. The syntax is DELETE TableName WHERE ColumnName = value; Allthe rows which satisfy the WHERE condition are deleted from the table. Use ‘statement to delete the rows of the Student table. > ; 137 Creating and Moditying Tables4.8 Querying Tables To retrieve data from a table the Select statement is used. The format OF the statement is: SELECT Columnl, Column2, Column3, FROM TableName; The column names separated by commas: should be specified after the keywo, Select. The tables which contain the columns are specified after the Fro, clause. Select and From are clauses necessary for every SQL retrieval state ment. Every SQL statement is terminated by a";" which starts execution of the statement. The result of a query is a table and is displayed in a tabular form, Users can query data from: tablescreated by them or! tablescreated by otherusers to which they have authorised access. The Select statement is one of the most powerful and complex SQL statement. An order: cannot be assumed in display. ing rows. Example: To list the Locations of all branches SELECT BCode, Location FROM BRANCH; BCode _ Location BBY Bombay DEL Delhi MAS Madras To retrieve data from certain columns of the table column names have tole specified. To retrieve all the columns of the table a "*" is used ins! individual column names. The format of the statement is: SELECT * FROM TableName; Using the above syntax we can retrieve data from the branch table. The valué in the four columns of the table Branch (BCode, Location, Targ? YTDSa les) will be displayed.Pome Example Display the jobs held in the organization SELECT DISTINCT Title FROM SalesRep; TITLE. Sales Mgr Sales Rep vp Sales 5.4 Select From Where (Relational Operators) SQL queries that retrieve all the rows in a table are used mainly for repox generation. To select only certain rows from the table that satisfy a particular condition the WHERE clause is used. The keyword WHERE is followed by the condition. The condition is applied to every row of the table: If the conditions ‘TRUE, the rowis displayed. If the condition is FALSE, the row is excluded. Ifthe condition is NULL, the row is displayed. SQL allows a large number of cond: tional tests to be performed. The Comparison test, compares the value of the one expression to the value of another expression. The character and date values must be enclosed in single quotes. The values in the Tite column of the SalesRep table are compared agaits the string constant Sales Rep. When Sales Rep occurs in the Title colum then the values in the columns Name and Tite are displayed for that row: Example : Display all the Sales Representatives SELECT Name, Title FROM SalesRep WHERE Title = ‘Sales Rep’; Design & implementation 76 of Oracle DBMSNaN. TITLE gwati Usgaonkar Sales Rep gunanda Rao Sales Rep chandra Mohan Sales Rep 5.5 Select From Where (Relational Operators) ‘The Conditional test to check whether the values in the column Rate of the Item table are greater than 2000. Only the rows where Rate of the item exceeds Rs.2000 are selected and values in the columns It emCode and Description are displayed. The Rate column is used in the WHERE clause to specify the criteria to select rows. It isnot necessary to select the Rate column inthe SELECT clause. Example List the code and the names of items whose price is below Rs. 2000/- SELECT ItemCode, Description FROM Item WHERE Rate < 2000; ITEMCODE DESCRIPTION SRNL Journals FLPY360 360kB Floppies ‘LGHPN: Lightpens ‘KBD84 84key Keyboard 5.6 Select From Where (Dates) Toselect the Order number and Order date of the orders placed after the 1st of August 1991, condition OrdDate > ‘1-Aug-91" , is specified in the WHERE clause of the SELECT statement. The date constant to be compared against the column value has to be enclosed in single quotes. The date can also be written as ‘1- Aug- 91’. The month name can be entered in upper case or lower case. The dashes are mandatory. i 2 Data Retrieval CommandsOe PTE Seer Example List the order numbers for the orders received after Ist August 1991. SELECT OrderNo , OrdDate FROM Orders WHERE Orddate > ‘01-AUG-91' 7 ORDERNO ORDDATE. { 83 } 82 02-AUG-91 | 85 02-AUG-91 { 84 13-AUG-91 86 13-AUG-91 5,7 Select From Where (Between...And) The Range test checks whether the result of an expression falls within ty specified range. BETWEEN . . . AND is the SQL range operator. It checks whet the values in the ROL column of the ITEM table are greater than or equal toitt butless than or equal to 1000. Only those values that fall in the rangeare selected Example List the Itemcode of the Items whose reorder level lies between 100 and 1001 COLUMN ROL FORMAT 9,990.00; SELECT ItemCode, ROL ReOrderLevel FROM Item WHERE ROL BETWEEN 100 AND 1000 ; ITEMCODE REORDERLEVEL KBD84 1000 KBD101 500 ‘vDuU12 1000 vpu14 500 | SRNL 500 Design & 30 of Oracle DBMSject From Where (In) : 7 ‘hecks whether the resuli ship test that c result of an expression Merb t. The SQL membershi i Fishes the noel ales in the sel SHIP test is performed by the rn tor column Tite contains thestring sales Rey i P Or Sales Mor thatrow e vected and the values in the Name and Tit1e column are displayed. ple ah the list of Sales persons who are either SalesReps or Sales Managers, seecT Name, Title FROM SalesRep WHERE Title IN ( ¢ Sales Rep’, ‘Sales mgr’); we TITLE x sanjay, Sawant Sales Mgr gvati Usgaonkar Sales Rep Sunanda Rao Sales Rep Chandra Mohan Sales Rep 59 Select From Where (Is Null) InaRelational Database, tables are used to aremany cases when a particular value is ses, ORACLE allows us Tepresent real world variables. There not known or does not exist. In such to define the value asa null. A NULL valueis different fom spaces or zero. It indicates the absence of data or that the value is not known. Two null valu 'es are not equal. The IS NULL operator is used to detect thenull values in a Particular column. I$ NOT NULL operator is used to detect } Columns where the values are not null.Logout of UNIX Ifyou wish to discontinue after quitting SQL*Plus, then you must Logout of the ‘UNIX operating system. Type
D at the UNIX prompt. %
D 4.11 Summary The Oracle software comprises of the RDBMS and the various products Some of the Oracle products are SQL*Plus, SQL*Forms, SQL*Calc, SQL*Menu, SQL*Graph, SQL*Report, SQL*Net, Pro*C and Pro*COBOL SQL*Plus is - ANon Procedural Language - ADataSublanguage - Nota Database Management System - Embedded in 3GLs The SQL*Plus commands for some DBMS functions are: CREATE TABLE, CREATE VIEW, ALTER TABLE, DROP TABLE, SELECT INSERT, DELETE, UPDATE, GRANT, REVOKE, SHARE LOCK, COMMIT, ROLLBACK Each user should have a valid Login Name and Password DESCRIBE or DESC command can beused to display the tabledefinition SELECT command is used to query the table SELECT and FROM clause are necessary for every SQL query SQL*Plus has commands to append, insert and edit the current SQL command Query results are formatted using the COLUMN command QUIT or EXIT allows you to Logout of SQL*Plus oF Introduction fo SQL* Pius4.12 Learn Yourself Fill in the blanks 1. SQL names have be a maximum of characters in length, 2. ______ command displays table definitions. 3. ______and__ clauses are essential in a query Staternen, } 4, Column names are specified after the clause, 5. Tables containing columns are specified after the cla Multiple Choice 1. SQL*Plus can be classified as a. a Relational Database Management System b. an Interactive Query processor c. an Interactive Relational Database 2° SQL*Plus isa a. Procedural Language b. Non Procedural Language c. Programming Language | 3. SELECTisa a. Data Manipulation Command { b. Data Definition Command c. Data Retrieval Command 4. SQL cannot be used for integrity control of the database. a. The above statement is true b. The statement is false c. None of the above 5. Which of the following statements is false, a. COLUMN command can be used to format character values. b. | COLUMN command can be used to format numeric values. ¢ — COLUMN command can be used to format date values. OeSY, a v oll 5.15 Summary * Thecolumns in the SELECT and WHERE clause must belong to the tay in the FROM clause Conditions can be imposed on query results by WHERE clause The default date format is DD-MMM-Yy Date values are enclosed in single quotes BETWEEN. .AND. . operator is used to . Specify a range of values * The IN operator is used when column values have to be compare toa list of values * NULL indicates absence of data * ANULL value is different from Spaces or zero * Two null values are Not equal * IS NULL operator ig used to detect the null values . * LIKE operator is used to select rows that match a pattern of, characters . * Wildcard % matches any or no characters * Wildcard _ matches exactly one character * The operators that can be used Ma WHERE clause are: > ds < <= ls AL AND OR Nor 7 BETWEEN. . AND TS NULL IN LIKE * The precedence Of the operators are: 1. The following have equal Precedence = Is oy < >= <= BETWEEN ... AND IN LIKE IS NULL 2 Nor AND ORo yourself gf e default column headings _ are used. $ prank’ we ochange th ' f val range 1 A jues can be specified by the__operator. operator is used to detect null values. eed aoe a pattern of characters the____ operator is used. To noice ‘The results of the query are displayed in A ascending order p, descending order ¢ _arandom order The WHERE clause in a SELECT statement is used to a. _ select columns conditionally b. _ select both rows and columns conditionally
You might also likeDbmslecturenotes 100212060546 Phpapp02PDFNo ratings yetDbmslecturenotes 100212060546 Phpapp0239 pagesSQL Notes FinalPDFNo ratings yetSQL Notes Final50 pagesRec 75PDFNo ratings yetRec 7581 pages0.0.1 SQLPDFNo ratings yet0.0.1 SQL73 pagesThe Database Language SQLPDFNo ratings yetThe Database Language SQL82 pagesDatabase PracticalPDFNo ratings yetDatabase Practical30 pagesChapter 6- SQLPDFNo ratings yetChapter 6- SQL40 pagesSQL Study Material PDFPDF100% (1)SQL Study Material PDF62 pagesTructured Uery Anguage: Path From Unorganized To OrganizedPDFNo ratings yetTructured Uery Anguage: Path From Unorganized To Organized10 pagesSQL - Structured Query LanguagePDFNo ratings yetSQL - Structured Query Language24 pagesRdbms FilePDFNo ratings yetRdbms File46 pagesLecture 7 SQLPDFNo ratings yetLecture 7 SQL88 pagesChapter 6PDFNo ratings yetChapter 683 pagesISM-AYUSH BANSAL Practical file-BBA 212PDFNo ratings yetISM-AYUSH BANSAL Practical file-BBA 21220 pagesOracle RDBMS & SQL Tutorial (Very Good)PDF100% (7)Oracle RDBMS & SQL Tutorial (Very Good)66 pagesRelated titlesClick to expand Related TitlesCarousel PreviousCarousel NextDbmslecturenotes 100212060546 Phpapp02PDFDbmslecturenotes 100212060546 Phpapp02SQL Notes FinalPDFSQL Notes FinalRec 75PDFRec 750.0.1 SQLPDF0.0.1 SQLThe Database Language SQLPDFThe Database Language SQLDatabase PracticalPDFDatabase PracticalChapter 6- SQLPDFChapter 6- SQLSQL Study Material PDFPDFSQL Study Material PDFTructured Uery Anguage: Path From Unorganized To OrganizedPDFTructured Uery Anguage: Path From Unorganized To OrganizedSQL - Structured Query LanguagePDFSQL - Structured Query LanguageRdbms FilePDFRdbms FileLecture 7 SQLPDFLecture 7 SQLChapter 6PDFChapter 6ISM-AYUSH BANSAL Practical file-BBA 212PDFISM-AYUSH BANSAL Practical file-BBA 212Oracle RDBMS & SQL Tutorial (Very Good)PDFOracle RDBMS & SQL Tutorial (Very Good)Footer menuBack to topAboutAbout Scribd, Inc.Everand: Ebooks & AudiobooksSlideShareJoin our team!Contact usSupportHelp / FAQAccessibilityPurchase helpAdChoicesLegalTermsPrivacyCopyrightDo not sell or share my personal informationSocialInstagram InstagramFacebook FacebookPinterest PinterestGet our free appsAboutAbout Scribd, Inc.Everand: Ebooks & AudiobooksSlideShareJoin our team!Contact usLegalTermsPrivacyCopyrightDo not sell or share my personal informationSupportHelp / FAQAccessibilityPurchase helpAdChoicesSocialInstagram InstagramFacebook FacebookPinterest PinterestGet our free appsDocumentsLanguage:English close menuEnglish(selected)EspañolPortuguêsDeutschFrançaisРусскийItalianoRomânăBahasa IndonesiaLearn moreCopyright © 2025 Scribd Inc.Language:English close menuEnglish(selected)EspañolPortuguêsDeutschFrançaisРусскийItalianoRomânăBahasa IndonesiaLearn moreCopyright © 2025 Scribd Inc.