as400 sql imp

Upload: moulikpl

Post on 14-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 As400 SQL Imp

    1/3

    SQL questions

    SQL / 400 Structured Query Language

    688. What is the stored procedure and how do you define a stored procedure.

    A stored procedure is a program that can be called to perform operations that can include both hostlanguage statements and SQL statements. Procedures in SQL provide the same benefits as procedures in ahot language. That is, a common piece of code need only be written and maintained once and can be calledfrom several programs. Stored procedures can be used in both distributed and non-distributed applicaitons.

    It is defined using DECLARE PROCEDURE statement, syntax is as belowEXEC SQLDELCARE P1 PROCEDURE(:PARM1 INOUT CHAR(10))(EXTERNAL NAME MYLIB/PROC1LANGUAGE RPGLESIMPLE CALL WITH NULLS);END-SQL

    We can have parameters as IN , OUT , INOUT type. Language can be RPGLE, C, CL, etc.. MYLIB/PROC1this PROC1 is a program written and compiled separately and it is of language which you are specifying insection LANGUAGE.

    689. Writing an SQL statement from selecting records from TWO files using single statement and Nestedselect statement.Using Single statement.SELECT * FROM FILE1, FILE2WHERE FILE1.FLD1 = FILE2.FLD1

    Using Nested Select statementSELECT * FROM FILE1WHERE FILE1.FLD1 EQ (SELECT FILE2.FLD1 FROM FILE2)

    690. How do you achieve referential integrity?By adding Referential Integrity Constraints to a Physical file or Logical file. Constraints like PRIMARY KEY,FOREGIN KEY, DELETE RULE, UPDATE RULE. ETC.Commands are ADDPFCST for Physical file and ADDLFCST for Logical file.

    Type of constraints*REFCST A referential constraint is being added*UNQCST A unique constraint is being added.*PRIKEY A primary key constraint is being added*CHKCST A check constraint is being added

    Type of Delete rule (DLTRULE)*NOACTION 1. Deleting a record in parent file is permitted (not restricted) if data for a non-null parent key does not match

    data for a foreign key.Deleting a record in a parent file is restricted (does not occur) if data for a non-null parent key matches datafor a foreign key.*RESTRICT Deleting a record in a parent file is permitted if data for a non-null parent key does not match data for aforeign key.Deleting a record in a parent file is restricted if data for a non-null parent key matches data for a foreign key.

    Classification: GE-GDC Internal

  • 7/29/2019 As400 SQL Imp

    2/3

    *CASCADE The cascade delete rule is used. Deleting a record in a parent file causes matching records in the dependentfile to be deleted when data for a non-null parent key matches data for a foreign key.

    Type of Update rule (UPDRULE)*NOACTION No Action

    *RESTRICT Updating a record in a parent file is permitted if data for a non-null parent key does not match data for aforeign key.Updating a record in a parent file is restricted if data for a non-null parent key matches data for a foreign key.

    691. Where Stored procedure lies in the system.If we want to have a look where the stored procedure, we can have a look through SQL.Select * from ?????????????????????

    692. Difference between View and Index ?View will not any data.. It only shows a data from table while Index has a Indexing Data for a sequence onwhich Index is created. View is similar to Logical file without having Key and Index is similar to Logical Filehaving Key (as keyed logical file has access path data) Table is similar to PF.

    693. Can we have records (with fields from more than one file) from multiple files and Nested / sub query inSQL ?Yes, we can have record from multiple file with join condition and we also can have nested query orsubquery like SELECT * FROM FILE1 WHERE FILE1.FLD1 IN (SELECT FILE2.FLD1 FROM FILE2)

    694. What is the sequence when using CURSOR?Define CursorDeclare CursorOpen CursorFetch recordProcessingClose Cursor

    695. Different type of Cursor?Two types of CursorSimple / Serial Cursor

    A serial cursor is one defined without SCROLL key wordFor serial cursor each row is fetched only once per OPENWhen it is opened it is positioned before the first row in the table.To use serial cursor we have to re-issue OPEN

    Scrollable Cursor which is defined with SCROLL key word.Cursor defined with SCROLL key wordRows of cursor can be fetched many timesWhen it is opened it is positioned before the first row in the table.When the FETCH is issued , the cursor is positioned to the row of the table that is specified by thePOSITION option. (FIRST, LAST, PREV, NEXT, RELATIVE)

    What is SQL?Ans:SQL is an interface for programming language.What is the values SQLCOD when there is an error in fetching the records specified in theselect statement?Ans:-ve value

    Writing an SQL statement from selecting records from TWO files using single statementand Nested select statement.

    Classification: GE-GDC Internal

  • 7/29/2019 As400 SQL Imp

    3/3

    Ans: Using Single statement.SELECT * FROM FILE1, FILE2WHERE FILE1.FLD1 = FILE2.FLD1

    Can we have records (with fields from more than one file) from multiple files and Nested /

    sub query in SQL ?

    Ans:Yes, we can have record from multiple file with join condition and we also can have nested

    query or subquery like SELECT * FROM FILE1 WHERE FILE1.FLD1 IN

    (SELECT FILE2.FLD1 FROM FILE2)

    What is the sequence when using CURSOR?

    Ans: Define Cursor ,Declare Cursor ,Open Cursor ,Fetch record ,Processing ,Close Cursor

    A program variable coded in an Embedded SQL statement is referred to as?Ans:Host Variable

    Why is the Declare cursor statement is used for?

    Ans:To define & name the cursor & specify rows to be fetched.

    What do we can do with the Embedded SQL statements?Ans:We can Insert/Update/Delete records, fetch records, fetch values from records intovariables.

    Classification: GE-GDC Internal