0% found this document useful (0 votes)
21 views3 pages

SQL Questions

IBM AS400 for SQL

Uploaded by

Moulikpl
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

SQL Questions

IBM AS400 for SQL

Uploaded by

Moulikpl
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 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 host language statements and SQL statements. Procedures in SQL provide the same benefits as procedures in a hot language. That is, a common piece of code need only be written and maintained once and can be called from several programs. Stored procedures can be used in both distributed and non-distributed applicaitons. It is defined using DECLARE PROCEDURE statement, syntax is as below EXEC SQL DELCARE P1 PROCEDURE (:PARM1 INOUT CHAR(10)) (EXTERNAL NAME MYLIB/PROC1 LANGUAGE RPGLE SIMPLE CALL WITH NULLS); END-SQL We can have parameters as IN , OUT , INOUT type. Language can be RPGLE, C, CL, etc.. MYLIB/PROC1 this PROC1 is a program written and compiled separately and it is of language which you are specifying in section LANGUAGE. 689. Writing an SQL statement from selecting records from TWO files using single statement and Nested select statement. Using Single statement. SELECT * FROM FILE1, FILE2 WHERE FILE1.FLD1 = FILE2.FLD1 Using Nested Select statement SELECT * FROM FILE1 WHERE 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 data for 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 a foreign 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

*CASCADE The cascade delete rule is used. Deleting a record in a parent file causes matching records in the dependent file 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 a foreign 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 on which Index is created. View is similar to Logical file without having Key and Index is similar to Logical File having 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 in SQL ? 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) 694. What is the sequence when using CURSOR? Define Cursor Declare Cursor Open Cursor Fetch record Processing Close Cursor 695. Different type of Cursor? Two types of Cursor Simple / Serial Cursor A serial cursor is one defined without SCROLL key word For serial cursor each row is fetched only once per OPEN When 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 word Rows of cursor can be fetched many times When 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 the POSITION 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 the select statement? Ans:-ve value Writing an SQL statement from selecting records from TWO files using single statement and Nested select statement.

Classification: GE-GDC Internal

Ans: Using Single statement. SELECT * FROM FILE1, FILE2 WHERE 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 into variables.

Classification: GE-GDC Internal

You might also like