Commands With Explanation - For Merge

download Commands With Explanation - For Merge

of 17

Transcript of Commands With Explanation - For Merge

  • 8/8/2019 Commands With Explanation - For Merge

    1/16

    2010-11

    BY MANINDERDEEP KAUR OF XI-D

    INFORMATIC PRACTICES

    PROJECT FILE

  • 8/8/2019 Commands With Explanation - For Merge

    2/16

    1. Commands with explanation, syntax and examples

    a. CREATE CREATE DATABASE EXPLANATION:Database is the container of tables. The database acts as a central point of administration forthe tables in the database.SYNTAX:CREATE DATABASE [ IF NOT EXISTS ] ;EXAMPLE:1. CREATE DATABASE MONEY ;2. CREATE DATABASE MGN ;CREATE TABLE EXPLANATION:Tables are defined with CREATE TABLE Command. When a table is created, its columns arenamed, data types and sizes are supplied for each column. Each table must have at least onecolumn.SYNTAX:CREATE TABLE ( [()], [()] .);EXAMPLE:1. CREATE TABLE EMPLOYEE (ecode int(3), ename char(20), sex char(1), grade char(2), gross

    decimal); 2. CREATE TABLE CLASS (rno int(2), student_name char(20), sex char(1), admno (4));

    CONSTRAINTS:UNIQUE CONSTRAINT:

    Explanation:

    This constraint ensures that no two rows have the same value in the specified column(s).

    Syntax:

    CREATE TABLE ( [()], [()] UNIQUE ..);

    Example:

    CREATE TABLE employee( ecode integer NOT NULL UNIQUE, ename char(20) NOT NULL);

    PRIMARY CONSTRAINT:

    Explanation:

  • 8/8/2019 Commands With Explanation - For Merge

    3/16

    This constraint declares a column as the primary key of the table. This constraint is similar tounique constraint except that only one column can be applied in the constraint.

    Syntax:

    CREATE TABLE ( [()], [()] PRIMARY KEY .);

    Example:

    CREATE TABLE employee(ecode integer NOT NULL PRIMARY KEY, ename char(20) NOT NULL);

    DEFAULT CONSTRAINT:

    Explanation:

    A default value can be specified for a column using the DEFAULT clause. When a user does not

    enter a value for the column(having default value), automatically the defined default value isinserted in the field.

    Syntax:

    CREATE TABLE ( [()], [()] DEFAULT .);

    Example:

    CREATE TABLE employee(ecode integer NOT NULL PRIMARY KEY, grade char(2) DEFAULT E1 );

    CHECK CONSTRAINT:

    Explanation:

    This constraint limits values that can be inserted into a column of a table.

    Syntax:

    Example:

    CREATE TABLE employee(ecode integer NOT NULL PRIMARY KEY, gross decimal CHECK(gross >2000);

    FOREIGN KEY CONSTRAINT:

    Explanation:

    Whenever two tables are related by a common column(or set of columns), then the relatedcolumn(s) in the parent table (or primary table) should be either declared a PRIMARY KEY or

  • 8/8/2019 Commands With Explanation - For Merge

    4/16

    UNIQUE KEY and the related column(s) in the child table should have FOREIGN KEYCONSTRAINT.

    Syntax:

    Columnname datatype (size) REFERENCES tablename [(columnname)] [ON UPDATE CASCADE];

    Example:

    CREATE TABLE items( itemsno char(5) NOT NULL PRIMARY KEY, );

    CREATE TABLE orders(orderno number (6,0) NOT NULL PRIMARY KEY, ..itemno char(5)REFERENCE items (itemno), );

    b. SELECT DISTINCT EXPLANATION:The DISTINCT keyword eliminates duplicate rows from the results of a SELECT statement. In theoutput there would be no duplicate rows. Whenever DISTINCT is used, only one NULL value isreturned in the results, no matter how many NULL values are encountered.SYNTAX:SELECT DISTINCT FROM ;EXAMPLE:1. SELECT DISTINCT CITY FROM SUPPLIERS; 2. SELECT DISTINCT SPECIES FROM PET;

    c. INSERT WITH DATE EXPLANATION:

    This function extracts the date part of a date or datetime expression.SYNTAX:DATE(expr)EXAMPLE:SELECT DATE( 2008-12-31 01:02:03 ) ;

    d. ORDER BY EXPLANATION:The ORDER BY clause allows the sorting of query results by one or more columns. The sortingcan be done either in ascending or descending order, the default order is ascending.SYNTAX:SELECT [, ..] FROM [where ] [ORDERBY ] ;EXAMPLE:SELECT * FROM EMPLOYEE ORDER BY ENAME;

    e. WHERE EXPLANATION:

  • 8/8/2019 Commands With Explanation - For Merge

    5/16

    SQL enables you to define criteria to determine which rows are selected for output. The WHEREclause in SELECT statement specifies the criteria for selection of rows to be returned.SYNTAX:SELECT [ ] FROM WHERE ;EXAMPLE:

    SELECT name, aggregate FROM student WHERE aggregate > 350 ;

    f. BETWEEN EXPLANATION:The BETWEEN operator defines a range of values that the column values must fall in to makethe condition true. The range includes both lower value and the upper value.SYNTAX:SELECT FROM WHERE BETWEEN AND ;EXAMPLE:SELECT * FROM members WHERE rno BETWEEN 10 AND 20 ;

    g. IN EXPLANATION:To specify a list of values, IN operator is used. The IN operator selects values that match anyvalue in a given list of values.SYNTAX:SELECT FROM WHERE IN ( 1998-01-31 ;

    COACH_ID COACHNAME AGE SPORTS DATOFAPP PAY SEX1 KUKREJA 35 KARATE 27/03/1996 1000 M2 RAVINA 34 KARATE 20/01/1998 1200 F3 KARAN 34 SQUASH 19/02/1998 2000 M4 TARUN 33 BASKETBALL 01/01/1998 1 5 00 M5 ZUBIN 36 SW IMMING 12/01/1998 7 5 0 M6 KETAKI 36 SW IMMING 24/02/1998 800 F7 ANKITA 39 SQUASH 20/02/1998 2200 F8 ZAREEN 37 KARATE 22/02/1998 1100 F9 KUSH 41 SW IMMING 13/01/1998 900 M

    10 SHAILYA 37 BASKETBALL 19/02/1998 1700 M

    Ans. i.

    SPORTSkaratekaratesquashbasketballswimmingswimmingsquash

    karateswimmingbasketball

  • 8/8/2019 Commands With Explanation - For Merge

    13/16

    ii.

    MOD(Age,5)4

    142iii.

    POWER(3,2)999

    iv.SubStr(CoachName,1,2)KURATAZUKU

    7. On the basis of following table, give the output i. SELECT TRUNCATE(AvgMar k) FROM STUDENT1W HERE AvgMar k < 75 ; ii. SELECT ROUND(AvgMar k) FROM STUDENT1W HERE GRADE = B ; iii. SELECT CONCAT(Name, Str eam) FROM STUDENT1 W HERE Class = 12A ; iv. SELECT RIGHT(Str eam, 2) f r om student1;

    No Name Stipend St r eam AvgMa r k Gr ade Class1 Kar an 400.00 Medical 78. 5 B 12B

    2 Divaka r 45 0.00 Comme r ce 89.2 A 11C3 Divya 300.00 Comme r ce 68.6 C 12C4 Ar un 3 5 0.00 Humanities 73.1 B 12C5 Sabina 5 00.00 Nonmedical 90.6 A 11A6 John 400.00 Medical 7 5 .4 B 12B7 Robe r t 2 5 0.00 Humanities 64.4 C 11A

  • 8/8/2019 Commands With Explanation - For Merge

    14/16

    8 Rubina 4 5 0.00 Nonmedical 88. 5 A 12A9 Vikas 5 00.00 Nonmedical 92.0 A 12A

    10 Mohan 300.00 Comme r ce 67. 5 C 12CAns. i.

    TRUNCATE(AvgMark)68736467ii.

    ROUND(AvgMark)

    797375iii.

    CONCAT(Name,Stream)RubinaNonmedicalVikasNonmedicaliv.

    Right(Stream,2)alceceesalales

    alalce

    8. On the basis of following table, give the output

  • 8/8/2019 Commands With Explanation - For Merge

    15/16

    i. SELECT UPPER(Title) FROM Libr a r y W HERE Pr ice < 1 5 0; ii. SELECT CONCAT(Author , Type) FROM Lib r a r y W HERE Qty < 3; iii. SELECT MOD(Qty, 4) FROM Libr a r y;

    No Title Author

    Type Pub Qty Price1 Data St r uctu r e Lipschutz DS McG r aw 4 217

    2 Compute r Studies F r ench FND Galgotia 2 7 5 3 Advance Pascal Schildt PROG McG r aw 4 3 5 04 Dbase dummies Palme r DBMS PustakM 5 1305 Maste r ing C++ Gur ewich PROG BPB 3 29 5 6 Guide Netwo r k Fr eed NET ZP r ess 3 2007 Maste r ing FoxP r o Seigal DBMS BPB 2 13 5 8 DOS guide No r ton OS PHI 3 17 5

    9 Basic Fo r Beginne r s Mo r ton PROG BPB 3 4010 Maste r ing W indows Cowa r t OS BPB 1 22 5

    Ans. i.

    UPPER(Title)COMPUTER SCIENCEDBASE DUMMIES

    MASTERING FOXPROBASIC FOR BEGINNERSii.

    CONCAT(Author,Type)FrenchFND

    DBMSSeigal OSCowart iii.

    MOD(Qty,4)0001

  • 8/8/2019 Commands With Explanation - For Merge

    16/16

    0000

    00