This action might not be possible to undo. Are you sure you want to continue?
Starting from Oracle8i one can use the "EXECUTE IMMEDIATE" statement to execute dynamic SQL and PL/SQL statements (statements created at runtime). Look at these examples. Note that the statements within quotes are NOT semicolon terminated: EXECUTE IMMEDIATE 'CREATE TABLE x (a NUMBER)'; Using bind variables... sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)'; EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location; Returning a cursor... sql_stmt := 'SELECT * FROM emp WHERE empno = :id'; EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id; One can also use the older DBMS_SQL package (V2.1 and above) to execute dynamic statements. Look at these examples: CREATE OR REPLACE PROCEDURE DYNSQL AS cur integer; rc integer; BEGIN cur := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE); rc := DBMS_SQL.EXECUTE(cur); DBMS_SQL.CLOSE_CURSOR(cur); END; / More complex DBMS_SQL example using bind variables: CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO %TYPE) AS v_cursor integer; v_dname char(20); v_rows integer; BEGIN v_cursor := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(v_cursor, 'select dname from dept where deptno > :x', DBMS_SQL.V7); DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no); DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1, v_dname, 20); v_rows := DBMS_SQL.EXECUTE(v_cursor); loop if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then exit; end if; DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1, v_dname);
DBMS_OUTPUT.PUT_LINE('Deptartment name: '||v_dname); end loop; DBMS_SQL.CLOSE_CURSOR(v_cursor); EXCEPTION when others then DBMS_SQL.CLOSE_CURSOR(v_cursor); raise_application_error(-20000, 'Unknown Exception Raised: '||sqlcode||' '|| sqlerrm); END; / What is the difference between %TYPE and %ROWTYPE? Both %TYPE and %ROWTYPE are used to define variables in PL/SQL as it is defined within the database. If the datatype or precision of a column changes, the program automically picks up the new definition from the database without having to make any code changes. The %TYPE and %ROWTYPE constructs provide data independence, reduces maintenance costs, and allows programs to adapt as the database changes to meet new business needs. %TYPE %TYPE is used to declare a field with the same type as that of a specified table's column. Example: DECLARE v_EmpName emp.ename%TYPE; BEGIN SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1; DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName); END; / %ROWTYPE %ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor. Examples: DECLARE v_emp emp%ROWTYPE; BEGIN v_emp.empno := 10; v_emp.ename := 'XXXXXXX'; END; / What is the result of comparing NULL with NULL?
b number := NULL. end if. DBMS_OUTPUT. NULL <> NULL'). Example: declare a number := NULL.NULL is neither equal to NULL. Look at this code example to convince yourself: declare a number := NULL.ename). nor it is not equal to NULL. The output would be: SQL> / Undefined NULL is neither = nor <> to NULL PL/SQL procedure successfully completed. Any comparison to NULL is evaluated to NULL.put_line('False. Use the NVL() or NVL2() function. . b number := NULL. end. else dbms_output. begin if nvl(a. 99999) = nvl(b. DECLARE v_EmpRecord emp%ROWTYPE. NULL = NULL').put_line('Undefined NULL is neither = nor <> to NULL'). end. b number := NULL.').'). elsif a<>b then dbms_output. BEGIN SELECT * INTO v_EmpRecord FROM emp WHERE ROWNUM = 1.PUT_LINE('Name = ' || v_EmpRecord. begin if a IS NULL and b IS NULL then dbms_output.put_line('True. end.[/code] Workarounds: Use IS NULL or IS NOT NULL: declare a number := NULL. 99999) then dbms_output. end if. begin if a=b then dbms_output.put_line('Both values are NULL. end if.put_line('Both values are NULL.
delete) statements in a function. one can use embedded SQL statements to obtain sequence values: select sq_sequence. You can have DML (insert.NEXTVAL. delete.PUT_LINE('Salary = ' || v_EmpRecord.sal).NEXTVAL into :i from dual. the workaround is to enforce the referential integrity through triggers as well.update. What is the difference between stored procedures and functions? Functions are normally used for computations where as procedures are normally used for executing business logic. However. / How does one get the value of a sequence into a PL/SQL variable? As you might know. Another way this error can occur is if the trigger has statements to change the primary. A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the result of a CASCADE delete. Etc. END. one cannot use sequences directly from PL/SQL. What is a mutating and constraining table? "Mutating" means "changing". A mutating table is a table that is currently being modified by an update. For example. If you must have triggers on tables that have referential constraints.DBMS_OUTPUT. There are several restrictions in Oracle regarding triggers: A row-level trigger cannot query or modify a mutating table. you cannot call that function from a SQL query. . procedures doesn't need to. But. When a trigger tries to reference a table that is in state of flux (being changed). it is considered "mutating" and raises an error since Oracle should not return data that has not yet reached its final state. foreign or unique key columns of the table off which it fires. (Of course. you cannot call such a function in a SQL query. Oracle (for some silly reason) prohibits this: i := sq_sequence. or insert statement. NEW and OLD still can be accessed by the trigger). if you have a function that is updating a table. Functions MUST return a value.
Example while writing a stored procedure that uses table named tabl1 and tabl2 etc.select myFunction(field) from sometable. User Defined Functions (UDFs). One of the advantages of User Defined Functions over Stored Procedures. . A procedure may modify an object where a function can only return a value. When advantages or disadvantages of User Defined Functions are discussed. UPDATE. Stored procedure returns always integer value by default zero. **************************************************************** Difference between user defined function and stored procedure Advantages of User Defined Functions Before SQL 2000. The DML statements INSERT. and DELETE cannot be used on base tables. Stored Procedures were often used in their place. User Defined Functions are simpler to invoke than Stored Procedures from inside another SQL statement. or Case statement. Disadvantages of User Defined Functions User Defined Functions cannot be used to modify base table information. a different value is returned. will throw error. Stored procedure is precompiled execution plan where as functions are not.but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution. In addition. Where. GETDATE cannot be called from inside a UDF you create. Function returns 1 value only. At that stage procedures executed faster than triggers as triggers had to be re-compiled every time before executed (unless cached).. Every time the function is called. the comparison is usually to Stored Procedures. Another disadvantage is that SQL functions that return non-deterministic values are not allowed to be called from inside User Defined Functions. Therefore. Stored Procedure: supports deferred name resolution. Procedure can return multiple values (max 1024). PS: In earlier releases of Oracle it was better to put as much code as possible in procedures rather than triggers. where as function return type could be scalar or table or table values(SQL Server). were not available. GETDATE is an example of a non-deterministic function. In more recent releases both triggers and procedures are compiled when created (stored p-code) and one can add as much code as one likes in either procedures or triggers. They also can be used to create joins. is the fact that a UDF can be used in a Select.
The final UDF is a Multi-statement Table Function. Each type refers to the data being returned by the function.@InDateTime. From inside Query Analyzer. This function should be shortened to: CREATE FUNCTION testDateOnly(@InDateTime datetime) RETURNS varchar(10) AS BEGIN RETURN CONVERT(varchar(10).DateOnly(@InDateTime datetime) RETURNS varchar(10) AS BEGIN DECLARE @MyOutput varchar(10) SET @MyOutput = CONVERT(varchar(10).101) RETURN @MyOutput END To call our function. Declaring the output variable was for clarity only. Any built in function that is non-deterministic. a date time value will be passed in. similar to a Create Table statement. DBO in this case. This function returns a table variable whose structure was created by hand. GETDATE can be used as the input parameter. and @@PACK_SENT. It is useful when complex data manipulation inside the function is required. NEWID. Other built in SQL functions that cannot be used inside a User Defined Function include: RAND.101) END . Scalar UDFs Our first User Defined Function will accept a date time. Scalar functions return a value. @@TIMETICKS. Scalar functions return a single value. Between the BEGIN and END block is the statement code.Types of User Defined Functions There are three different types of User Defined Functions. @@CONNCECTIONS. but could not be used inside the function itself.@InDateTime. execute: SELECT dbo.DateOnly(GETDATE()) Notice the User Defined Function must be prefaced with the owner name. enter: CREATE FUNCTION dbo. and return only the date portion. In Line Table functions return a single table variable that was created by a select statement. In addition. The statement begins by supplying a function name and input parameter list. The next line defines the type of data the UDF will return. In this case.
Error handling is restricted. They are a special data type whose scope is limited to the process that declared it. and data in it will be manipulated prior to the return: . Almost like a simply constructed non-updatable view. There are a number of restrictions unique to functions though. None of my personal testing has found this result though. This new function will accept the same input parameter. The return is a Table Variable. In Query Analyzer. In addition. a specific table will be created. But rather than return a table from a simple select. The Multi Statement UDF will always return a table variable–and only one table variable. Multi Statement UDFs Multi Statement User Defined Functions are very similar to Stored Procedures. Like other programming languages. but having the benefit of accepting input parameters. For a Multi Statement test.LookByFName(@FirstLetter char(1)) RETURNS TABLE AS RETURN SELECT * FROM employee WHERE LEFT(fname. There is no way to return multiple result sets. enter and run: USE pubs GO CREATE FUNCTION dbo.LookByFName(’A') All the rows having a first name starting with A were returned. not to be confused with a temporary table. 1) = @FirstLetter To use the new function. They both allow complex logic to take place inside the function.Inline Table UDFs These User Defined Functions return a table variable that was created by a single select statement. a User Defined Function cannot call a Stored Procedure from inside itself. Table variables are new in SQL 2000. enter: SELECT * FROM dbo. the purpose of a User Defined Function is to create a stand-alone code module to be reused over and over by the global application. we will create a modified version of the LookByFName function. So GETDATE and RAND cannot be used. This next function looks all the employees in the pubs database that start with a letter that is passed in as a parameter. RAISERROR and @@ERROR are invalid from inside User Defined Functions. Table variables are stated to have performance benefits over temporary tables. that UDFs cannot use non-deterministic built in functions. They also cannot execute dynamic SQL. Remember also.
we can manipulate data like a Stored Procedure.multi_test(@FirstLetter char(1)) RETURNS @Result TABLE ( fname varchar(20).fname Conclusion User Defined Functions offer an excellent way to work with code snippets. f. SELECT fname FROM dbo. execute: SELECT * FROM dbo. hire_date FROM employee WHERE LEFT(fname. Not being able to use non-deterministic built in functions is a problem.lname. .fname FROM employee e INNER JOIN dbo. but if it can be worked around. hire_date datetime. only specific columns can be returned. hire_date) SELECT fname.multi_test(’A') With the new Multi Statement Function. on_probation char(1) ) AS BEGIN INSERT INTO @Result (fname. For example. 1) = @FirstLetter UPDATE @Result SET on_probation = ‘N’ UPDATE @Result SET on_probation = ‘Y’ WHERE hire_date < ‘01/01/1991′ END RETURN To use the new function. The main requirement is that the function be self-contained. UDFs will provide you with a programming plus.multi_test(’A') f ON e. but use it in statement areas like a View.CREATE FUNCTION dbo.multi_test(’A') The function can also be joined like a view: SELECT e.fname = f.
sp_who2. 35. 41. 36. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db. Views also reduce the effort that is required for writing queries to access specific columns every time. 40. We can also have user defined stored procedures which can be called in similar way What is a trigger? Ans: Triggers are basically used to implement business rules.What is an Index? Ans: When queries are run against a db. 39. So the Process of organizing this data into tables is actually referred to as normalization.What is the basic difference between clustered and a non-clustered index? Ans: The difference is that. an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.SQL SERVER:34. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. 37. The difference is that it can be activated when data is added or edited or deleted from a table in a database.What is a view? Ans: If we have several tables in a db and we want to view only specific columns from specific tables we can go for views.What is a Stored Procedure? Ans: Its nothing but a set of T-SQL statements combined to perform a single task of several tasks.What are cursors? .What are the types of indexes available with SQL Server? Ans: There are basically two types of indexes that we use with the SQL Server. sp_renamedb are a set of system defined stored procedures.Can you give an example of Stored Procedure? Ans: sp_helpdb . Clustered index is unique for any given table and we can have only one clustered index on a table. you actually run a set of statements. 38. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index.What is normalization? Ans: Well a relational database is basically composed of tables that contain related data. Clustered and the Non-Clustered. Its basically like a Macro so when you invoke the Stored procedure. Triggers is also similar to stored procedures.
SQL Server runs on which TCP/IP port? Ans: SQL Server runs on port 1433 but we can also change it for better security. We use these commands to check the consistency of the databases. 48.When do we use the UPDATE_STATISTICS command? Ans: This command is basically used when we do a large processing of data. UPDATE_STATISTICS updates the indexes on these tables accordingly.e.To check that all pages in a db are correctly allocated. i.Can you give me some DBCC command options?(Database consistency check) Ans: DBCC CHECKDB . 45.It gives report on current usage of transaction log in percentage. 46. 43. 49. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.Can you tell me the difference between DELETE & TRUNCATE commands? Ans: Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. we need to basically update the indexes to take these changes into account.Ans: Well cursors help us to do an operation on a set of data that we retreive by commands such as Select columns from table. If we do a large amount of deletions any modification or Bulk Copy into the tables. maintenance.. DBCC CHECKFILEGROUP .Checks all tables file group for any damage. For example : If we have duplicate records in a table we can remove it by declaring a cursor which would check the records during retreival one by one and remove rows which have duplicate values. 44. 47. validation task and status checks.Can we use Truncate command on a table which is referenced by FOREIGN KEY? Ans: No. 'newname' 50.Ensures that tables in the db and the indexes are correctly linked.What command do we use to rename a db? Ans: sp_renamedb 'oldname' . We cannot use Truncate command on a table with Foreign Key because of referential integrity.both on client and the server.Well sometimes sp_reanmedb may not work you know because if some one is using the db it will not accept this command so what do you think you can do in such cases? .and DBCC CHECKALLOC . DBCC SQLPERF . 42.From where can you change the default port? Ans: From the Network Utility TCP/IP properties --> Port number.What is the use of DBCC commands? Ans: DBCC stands for database consistency checker.
What is a Linked Server? Ans: Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. 51. sp_addlinkedsrvlogin 59.Can you explain the role of each service? Ans: SQL SERVER .How do you troubleshoot SQL Server if its running very slow? . WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. 52. failed jobs etc.case insensitive and Binary.What are the OS services that the SQL Server installation adds? Ans: MS SQL SERVER SERVICE. Outer Join.Ans: In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode.is for running the databases SQL AGENT .What is a Join in SQL Server? Ans: Join actually puts data from two or more tables into a single result set. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group. Backups DTC . There are three types of sort order Dictionary case sensitive.Is for linking and connecting to other SQL Servers 61. Ans: We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. 56. 57. 53. 54. DB Maintanance.is for automation such as Jobs. DTC (Distribution transac co-ordinator) 60. 58.Can you explain the types of Joins that we can have with Sql Server? Ans: There are three types of joins: Inner Join. Cross Join 55. SQL AGENT SERVICE.What do you mean by COLLATION? Ans: Collation is basically the sort order.When do you use SQL Profiler? Ans: SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running. Dictonary .What is the difference between a HAVING CLAUSE and a WHERE CLAUSE? Ans: Having Clause is basically used only with the GROUP BY function in a query.Can you link only other SQL Servers or any database servers such as Oracle etc..Which stored procedure will you be running to add a linked server? Ans: sp_addlinkedserver..
use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. If one server fails.Where do you think the users names and passwords will be stored in sql server? Ans: They get stored in master db in the sysxlogins table.Lets say due to N/W or Security issues client is not able to connect to server or vice versa. Secondly. 67.What are the authentication modes in SQL Server? Ans: Windows mode and mixed mode (SQL & Windows). From Enterprise Manager we can configure the logshipping. 65.but I think we have a command to do it). How do you troubleshoot? Ans: First I will look to ensure that port settings are proper on server and client Network utility for connections.Let us say the SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow? Ans: For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db. the other server will have the same db and we can use this as the DR (disaster recovery) plan. 64. Third would be to run UPDATE_STATISTICS command to update the indexes 62.Let us say master db itself has no backup. 63.Enterprise Editions.What is log shipping? Can we do logshipping with SQL Server 7. Now you have to rebuild the db so what kind of action do you take? Ans: (I am not sure. What is a CO-RELATED SUBQUERY A CO-RELATED SUBQUERY is one that has a correlation name as table or view designator in the FROM clause of the outer query and the same correlation name as a qualifier of a search condition in the WHERE clause of the subquery. eg SELECT field1 from table1 X WHERE field2>(select avg(field2) from table1 Y where . Makepipe is run on Server and readpipe on client to check for any connection issues. We should have two SQL Server . In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. 66.0 Ans: Logshipping is a new feature of SQL Server 2000. ODBC is properly configured at client end for connection ------Makepipe & readpipe are utilities to check for connection.Ans: First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor.
field1=X. (The subquery in a correlated subquery is revaluated for every row of the table or view named in the outer query. Outer Join–Its a join condition used where One can query all the rows of one of the tables in the join condition even though they don’t satisfy the join condition. What are various constraints used in SQL NULL NOT NULL CHECK DEFAULT What are different Oracle database objects TABLES VIEWS INDEXES SYNONYMS SEQUENCES TABLESPACES etc What is difference between Rename and Alias Rename is a permanent name given to a table or column whereas Alias is a temporary name given to a table or column which do not exist once the SQL statement is executed. its a virtual table. whereas a column that compose a UNIQUE is not automatically defined to be .) What are various joins used while writing SUBQUERIES Self join-Its a join foreign key of a table references the same table.field1). What is a view A view is stored procedure based on one or more tables. Equi-join–Its a join condition that retrieves rows from one or more tables in which one or more columns in one table are equal to one or more columns in the second table. What are various privileges that a user can grant to another user SELECT CONNECT RESOURCE What is difference between UNIQUE and PRIMARY KEY constraints A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL.
DROP old_table RENAME new_table TO old_table DELETE FROM table_name A WHERE rowid NOT IN (SELECT MAX(ROWID) FROM table_name GROUP BY column_name) What is difference between SUBSTR and INSTR SUBSTR returns a specified portion of a string eg SUBSTR(’BCDEF’. SQL is a language used to query the relational database(DML.Present the data in a different perspective from that of the base table. eg INSTR(’ABC-DC-F’.2) output 7 (2nd occurence of ‘-’ ) ******************************************************************* Can a view based on another view? Yes.4) output BCDE INSTR provides character position in which a pattern is found in a string. CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table.DCL.table_no). What are the advantages of views? . Edit SQL commands and PL/SQL. .mandatory must also specify the column is NOT NULL. Set options. Which datatype is used for storing graphics and images LONG RAW data type is used for storing BLOB’s (binary large objects). SQL*PLUS commands are used to format query result. .DDL).Store complex queries.Simplify commands for the user.table_no=A. Can a primary key contain more than one columns Yes How you will avoid duplicating records in a query By using DISTINCT What is difference between SQL and SQL*PLUS SQL*PLUS is a command line tool where as SQL and PL/SQL language interface and reporting tool.'-’. .Provide an additional level of table security. . by restricting access to a predetermined set of rows and columns of a table. .Hide data complexity. Its a command line tool that allows user to type SQL commands to be executed directly against an Oracle database. How will you delete duplicating rows from a base table DELETE FROM table_name A WHERE rowid>(SELECT min(rowid) from table_name B where B.
What is a Tablespace? A database is divided into Logical Storage Unit called tablespace. How are the index updates? Indexes are automatically maintained and used by Oracle.Provide public access to an object . . Once created a data file can't change size. What are synonyms used for? . What are the Characteristics of Data Files ? A data file can be associated with only one database. What is an Oracle index? An index is an optional structure associated with a table to have direct access to rows. view. views or program units of a remote database. Changes to table data are automatically incorporated into all relevant indexes. How to define Data Block size ? A data block size is specified for each ORACLE database when the database is created. What is a public synonym? Any database user can access a public synonym. What are the types of synonyms? There are two types of synonyms private and public. A tablespace is used to grouped related logical structures together What is Rollback Segment ? A Database contains one or more Rollback Segments to temporarily store "undo" information.ORA file and can’t be changed latter. What is a synonym? A synonym is an alias for a table. sequence or program unit.What is an Oracle sequence? A sequence generates a serial list of unique numbers for numerical columns of a database's tables.Simplify the SQL statements for database users. Index can be created on one or more columns of a table. A database users and allocated free database space in ORACLE data blocks. What is a private synonym? Only its owner can access a private synonym. which can be created to increase the performance of data retrieval. . One or more data files form a logical unit of database storage called a tablespace. .Mask the real name and owner of an object. Block size is specified in INIT.Provide location transparency for tables.
but the performance cost is significant. Look at this example for creating and Oracle 9i database: CONNECT SYS AS SYSDBA ALTER SYSTEM SET DB_CREATE_FILE_DEST='/u01/oradata/'. as it is quite involved and error prone. however. One can also create databases manually using scripts. ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_1='/u02/oradata/'. or be multiples of your operating system block size. One can use smaller block sizes. parameter of the ALTER SESSION Command ? The Optimizer chooses Cost_based approach and optimizes with the goal of best throughput if statistics for atleast one of the tables accessed by the SQL statement exist in the data dictionary.What does a Control file Contain ? A Control file records the physical structure of the database. ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_2='/u03/oradata/'. What is difference between UNIQUE constraint and PRIMARY KEY constraint ? A column defined as UNIQUE can contain Nulls while a column defined as PRIMARY KEY can't contain Nulls. What is the effect of setting the value "CHOOSE" for OPTIMIZER_GOAL. What is the effect of setting the value "ALL_ROWS" for OPTIMIZER_GOAL parameter of the ALTER SESSION command ? What are the factors that affect OPTIMIZER in choosing an Optimization approach ? Answer The OPTIMIZER_MODE initialization parameter Statistics in the Data Dictionary the OPTIMIZER_GOAL parameter of the ALTER SESSION command hints in the statement. CREATE DATABASE. Otherwise the OPTIMIZER chooses RULE_based approach. is falling out of fashion. Your choice should depend on the type of application you are . Time stamp of database creation. How does one create a new database? (for DBA) One can create and modify Oracle databases using the Oracle "dbca" (Database Configuration Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin directory. This option. What database block size should I use? (for DBA) Oracle recommends that your database block size match. The Oracle Universal Installer (oui) normally starts it after installing the database server software. It contains the following information. Database Name Names and locations of a database's files and redolog files. What is Index Cluster ? A Cluster with an index on the Cluster Key When does a Transaction end ? When it is committed or Rollbacked.
Where 'n' is the tablespace number you get from SELECT TS#. How does one prevent tablespace fragmentation? (for DBA) Always set PCTINCREASE to 0 or 100.DBA_FREE_SPACE_COALESCED dictionary view. command. until then use: SQL> alter session set events 'immediate trace name coalesce level n'. How does one coalesce free space ? (for DBA) SMON coalesces free space (extents) into larger. 400K. If you have many small transactions as with OLTP. What does ROLLBACK do ? ROLLBACK retracts any of the changes resulting from the SQL statements in the transaction. Such extents of bizarre size are rarely re-used in their entirety. 100K. A table's HWM can be calculated using the results from the following SQL statements: SELECT BLOCKS FROM DBA_SEGMENTS WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table).. 100K. SMON will not coalesce free space if a tablespace's default storage parameter "pctincrease" is set to 0. PCTINCREASE of 0 or 100 gives you nice round extent sizes that can easily be reused. Bizarre values for PCTINCREASE will contribute to fragmentation.g. use a larger block size. NAME FROM SYS. which contains the high water mark (HWM) for a table. You can get status information about this process by selecting from the SYS. as with a DSS application. only for a short period of time. If you are using a volume manager. unless they run into thousands and thousands where additional I/O may be required to fetch the additional blocks where extent maps of the segment are stored. etc. 102K. With fewer but larger transactions. For example if you set PCTINCREASE to 1 you will see that your extents are going to have weird and wacky sizes: 100K. 101K. etc. COALESCE.table ESTIMATE STATISTICS. Use the same extent size for all the segments in a given tablespace. Locally Managed tablespaces (available from 8i onwards) with uniform extent sizes virtually eliminates any tablespace fragmentation. use a smaller block size. With Oracle 7. 100K.running.. .TS$. Note that the number of extents per segment does not cause any performance issue anymore. contiguous extents every 2 hours and even then. ANALYZE TABLE owner. What are the different approaches used by Optimizer in choosing an execution plan ? Rule-based and Cost-based. 200K. consider your "operating system block size" to be 8K. This is because volume manager products use 8K blocks (and this is not configurable). E. SELECT EMPTY_BLOCKS FROM DBA_TABLES WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table)..3 one can manually coalesce a tablespace using the ALTER TABLESPACE . Where can one find the high water mark for a table? (for DBA) There is no single system table.
Oracle would also give it to you. Space allocation also depends upon the size of contiguous free space available.Thus. empno. The exception to this rule is locally managed tablespaces.(query result 2) . What does COMMIT do ? COMMIT makes permanent the changes resulting from all SQL statements in the transaction. Workaround: Do a user-level export of user A create new user B Import system/manager fromuser=A touser=B Drop user A ********************************************************* Display the records between two range select rownum. but it allocates 2 blocks or 16K as requested. The changes made by the SQL statements of a transaction become visible to other user sessions transactions that start only after transaction is committed. If one asks for 8 blocks and Oracle finds a contiguous free space that is exactly 8 blocks. What is COST-based approach to optimization ? Considering available access paths and determining the most efficient execution plan based on statistics in the data dictionary for the tables accessed by the statement and their associated clusters and indexes. Can one rename a database user (schema)? (for DBA) No. If one requests 16K or 2 blocks (assuming a 8K block size). Oracle doesn't round it up to the multiple of 5 when a tablespace is locally managed.1. How are extents allocated to a segment? (for DBA) Oracle8 and above rounds off extents to a multiple of 5 blocks when more than 5 blocks are requested. Enter value for upto: 10 Enter value for Start: 7 ROWNUM EMPNO ENAME ——— ——— ———1 7782 CLARK 2 7788 SCOTT . If it were 9 blocks. it would give it you.1 NOTE: You can also use the DBMS_SPACE package and calculate the HWM = TOTAL_BLOCKS . then Oracle allocates 64K or 8 blocks assuming 8K-block size. If one asks for 8 blocks.UNUSED_BLOCKS . ename from emp where rowid in (select rowid from emp where rownum <=&upto minus select rowid from emp where rownum< &Start). the tables' HWM = (query result 1) . Oracle doesn't round it up to 5 blocks. this is listed as Enhancement Request 158508. Clearly Oracle doesn't always round extents to a multiple of 5 blocks. Oracle will round it up to 10 blocks. If a tablespace is created with local extent management and the extent size is 64K.
0)). How do I write the query? SQL> select nvl(to_char(comm. PL/SQL declares all implicit cursors.).sal).sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b. cursor_name%NOTFOUND. cursor_name%ROWCOUNT. is called as Cursor. the cursor needs to be explicitly declared. For queries that returning more than one row. Find out nth highest salary from emp table SELECT DISTINCT (a. Output : NVL(TO_CHAR(COMM). Explicit Cursor attributes There are four cursor attributes used in Oracle cursor_name%Found. Here SQL%ISOPEN is false. SQL%ISOPEN Tips : 1. All are Boolean attributes. number or char or date Nvl(comm. SQL%NOTFOUND.sal<=b. cursor_name%ISOPEN Implicit Cursor attributes Same as explicit cursor but prefixed by the word SQL SQL%Found.’NA’) from emp.’NA’) ———————– NA 300 500 NA 1400 NA NA Oracle cursor : Implicit & Explicit cursors Oracle uses work areas called private SQL areas to create SQL statements. because oracle automatically closed the implicit cursor after executing SQL statements. instead of blank space. PL/SQL construct to identify each and every work are used. SQL%ROWCOUNT. For SQL queries returning a single row. : 2. if commission is null then the text “Not Applicable” want to display.sal)) FROM EMP B WHERE a. Enter value for n: 2 SAL .3 7839 KING 4 7844 TURNER I know the nvl function only allows the same data type(ie.
How to convert RAW datatype into TEXT? 22. How to create a database link ? 34. What are the Large object types suported by Oracle? 29. What is the difference between "translate" and "replace"? 14. Diffrence between a "where" clause and a "having" clause 5. How to remove duplicate records from a table? 16. What is a "trigger"? 25. What was the o/p for the following query 38.? 36. Explain normalization with examples. 20. 3. 31. What is a VIEW? How to get script for a view? 28. seelct 2 from the emp. What is the difference between "procedure" and "function"? 6. Explain Normalizationa dn Denormalization with examples. What is the diference between "NULL in C" and "NULL in Oracle?" 11. Talk about "Exception Handling" in PL/SQL? 10. 33. Why can a "group by" or "order by" clause be expensive to process? 26. What are the different types of joins? 2. Select the second row in the table 35. How will you copy the structure of a table without copying the data? 7.Primary Key and Aggregate Key 23. What is DYNAMIC SQL method 4? 15. Select even number in the the emp table. What is SQL*Loader? 30. How to find out the database name from SQL*PLUS command prompt? 8. Select the row between Third & 10th row. How functional dependency is related to database table design? 24. What is the difference among "dropping a table". When do you get contraint violtaion? What are the types of constraints? 21.*********************************************************************** * 1. Difference between "ORACLE" and "MICROSOFT ACCESS" databases. What cursor type do you use to retrieve multiple recordsets? 4. How to run SQL script from a Unix Shell? 18. Give some examples of Analytical functions. Difference between "VARCHAR" and "VARCHAR2" datatypes. What is Pro*C? What is OCI? 12. . What are "HINTS"? What is "index covering" of a query? 27.? 37. What is the use of ANALYZing the tables? 17. "truncating a table" and "deleting all records" from a table. Tadeoffs with having indexes 9. 32. 13. Difference . What is a "transaction"? Why are they necessary? 19.
Which command using Query Analyzer will give you the version of SQL server and operating system? 79.Decode. copy commit syntax 9.union and union all 11.Group by. Why truncating table is faster than delete 8.What is a sub-query? When would you use one? 73.Using query analyzer. Tradeoffs of using partitioned tables 15.What is the difference between a local and a global variable? 88. Which Ranking functions are available? 13.What are the different types of replication? How are they used? 87.What does it mean to have quoted_identifier on? What are the implications of having it off? 86.What are the different types of joins and what dies each do? 71.What is the purpose of using COLLATE in a query? 81. today it takes 6 minutes” 83.What is the difference between a Local temporary table and a Global temporary table? How is each one used? . NVL.What is a NOLOCK? 74.What is an execution plan? When would you use it? How would you view the execution plan? 84.What is a trigger? 82. How do we find row chaining? 5.What are the four main query statements? 72. Give 2 examples of avoiding unnecessary parsing. 1. Why EXISTS is preferable to distinct 18.. Difference . name 3 ways you can get an accurate count of the number of records in a table? 80. Difference . Difference .What is referential integrity? What are the advantages of it? 77.What are three SQL keywords used to change or set someone’s permissions? 75. Normalize many to many relationships 2.What is the difference between HAVING clause and the WHERE clause? 76. Difference . Order by clause 12.. What is TEMP table space in Oracle.Equijoin and union 3.What is the STUFF function and how does it differ from the REPLACE function? 85. NVL2 14. Pattern matching operators 6.What is one of the first things you would do to increase performance of a query? Example “ a query ran yesterday took 30 seconds. what is rollback segment 4. How can we call stored procedure in SQL query 16. Features in oracle 9i and 10g 7. Convert Zulu time zone to US Eastern time zone 10. 70.What is database normalization? 78.PL/SQL interview questions. What are the restrictions on calling PL/SQL from SQL 17.
Difference between Cluster and Non-cluster index? 111.What are tasks? 126.How do SQL server 2000 and XML linked? Can XML be used to access data? 95.Explain couple pf features of SQL server 2000(Scalability.What is the basic functions for master.How do you use DBCC statements to monitor various aspects of a SQL server installation? 92.What is indexing? 98.Can we rewrite subqueries into simple select statements or with joins? Example? 103.What is better. If yes what level and can it be controlled? 108.Difference between Function and Procedure-in general? 106.? 109. Group ByHaving? 114.0 to 2000? 119.Explain DBMS.Can a stored procedure call itself(recursive). msdb. RDBMS? 113.Difference between server.If a stored procedure is taking a table data type.How do we upgrade from SQL Server 6.89.transfer and server.0 and 7.What is a function? Give some example? 104.What id de-normalization and when do you do it? 101.What is the purpose of UPDATE STATISTICS? 91.Explain some DBCC commands? 121.How do you load large data to the SQL server database? 93.What is referential integrity and how is it achieved? 97.How do you find the number of rows in a table? 110.2nd Normal form or 3rd normal form? Why? 102. set commands? 122.How would you Update the rows which are divisible by 10.Explain the new features of SQL server 2000? 118.5 to 7. how it looks? .Explain sp_configure commands. Integration with internet.Explain basic SQL queries with SELECT from where Order By.What is a job? 125.Explain the basic concepts of SQL server architecture? 115.Can a stored procedure call another stored procedure.What are primary keys and foreign keys? 127. Availability.What is SQL server agent? 96.What is normalization and what are the different forms of normalizations? 99.Explain fundamentals of Data ware housing & OLAP? 117. if it does not have neither Cluster nor Non-cluster Index? 112. If yes what level and can it be controlled.What is data integrity? Explain constraints? 120.execute method? 100.How do you check the performance of a query and how do you optimize it? 94. etc.Difference between Function and Stored Procedure? 107.Explain what are db_options used for? 123.What are cursors? Name four types of cursors and when each one would be applied? 90. given a set of numbers in column? 128.)? 116. tempdb databases? 124.What is a stored procedure? 105.What is a table called.
3.How m-m relationships are implemented? 130.Questions regarding Raiseerror? 139.How do you measure the performance of a stored procedure? 138. Is it possible to do a FULL OUTER JOIN in MySQL? **************************************************************** .one with OR or one with IN? Where does MyISAM cache table records? Which will be faster out of queries with explicit INNER JOIN and implicit one? Is InnoDB faster/better than MyISAM? Is CHAR faster than VARCHAR? Is VARCHAR(80) faster than VARCHAR(255)? Are there performance issues when joining tables from different storage engines? If I change a derived table to a view. Using filesort” in the Extra column of EXPLAIN output.How do you find the error. will performance increase? If I see Using temporary. 8.How will oyu test the stored procedure taking two parameters namely first name and last name returning full name? 132.What are sub-queries? Give example? In which case sub-queries are not feasible? 135. 4.What are the type of joins? When do we use Outer and Self joins? 136. 2.How can you get @@error and @@rowcount at the same time? 134. Which will be faster out of these two queries . 9.129.Questions on identity? 140. 6. 7.If there is failure during updation of certain rows. does that mean a temporary table is created on disk? 10. how can you know the number of rows effected by last SQL statement? 133.How do you know which index a table is using? 131.Which virtual table does a trigger use? 137. what will be the state? **************************************************************** 1. 5.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.