Archive for the Oracle Category

Data movement using cursor and bulk insert – Oracle 11g

Posted in Oracle, Uncategorized with tags , , , , , , , on August 22, 2011 by DBAWork

If you want to store a collection of data from a cursor into a table, the “BULK COLLECT INTO, FORALL INSERT” in Oracle is a friend. Instead of iterating row-by-row through the cursor, BULK processes data in a batch mode at the background.

The syntax is a bit different in Oracle 10g and 11g. In the examples below, we will insert all the data from cursor into a table

CREATE TABLE MYTEST
( ”OBJECT_NAME” VARCHAR2(128 BYTE),
“OBJECT_ID” NUMBER,
“CREATED” DATE
);

The result set in the cursor has the same columns as the target table. Therefore, in 11g, we can simply code like

TYPE myrecord_tab_type IS TABLE OF MYTEST%ROWTYPE;
myrecord_tab myrecord_tab_type;

FETCH ref_cursor BULK COLLECT INTO myrecord_tab;

FORALL i IN 1 .. myrecord_tab.count
INSERT
INTO mytest
VALUES myrecord_tab(i);

In 10g, the code needs to be different and needs to use DBMS_SQL.XXXX_TABLE.

TYPE myrecord_tab_type IS RECORD
(
NAME DBMS_SQL.VARCHAR2_TABLE,
ID DBMS_SQL.NUMBER_TABLE,
DATE DBMS_SQL.DATE_TABLE
);
myrecord_tab myrecord_tab_type;

FETCH ref_cursor BULK COLLECT INTO myrecord_tab.name, myrecord_tab.id, myrecord_tab.date;

FORALL i IN 1 .. myrecord_tab.name.count
INSERT
INTO mytest(object_name, object_id, created)
VALUES (myrecord_tab.name(i), myrecord_tab.id(i), myrecord_tab.date(i));

Remote Oracle Support,DBAWorkDatabase support, Database services, Oracle ADF

Advertisements

System Databases – SQL Server

Posted in DB2, General, Oracle, SQL Server with tags on June 3, 2011 by DBAWork

Microsoft SQL Server is a relational database server developed by Microsoft : It is a software product whose primary function is to store and retrieve data as requested by other software applications, be it those on the same computer or those running on another computer across a network (including the Internet). There are at least a dozen different editions of Microsoft SQL Server aimed at different audiences and for different workloads (ranging from small applications that store and retrieve data on the same computer, to millions of users and computers that access huge amounts of data from the Internet at the same time).

Master DB

Records all the system-level information for an instance of SQL Server.
This includes instance-wide metadata such as logon accounts, endpoints, linked servers, and system configuration settings.
Also, master is the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server.
Therefore, SQL Server cannot start if the master database is unavailable.

msdb DB

It is used by SQL Server Agent for scheduling alerts and jobs and by other features such as Service Broker and Database Mail.

model DB

Is used as the template for all databases created on the instance of SQL Server. Modifications made to the model database, such as database size, collation, recovery model, and other database options, are applied to any databases created afterward.

ResourceDB

Is a read-only database that contains system objects that are included with SQL Server. SQL Server system objects, such as sys.objects are physically persisted in the Resource database, but they logically appear in the sys schema of every database.

Tempdb DB

It is a global resource that is available to all users connected to the instance of SQL Server and is used to hold the following:

  • Temporary user objects that are explicitly created, such as: global or local temporary tables, temporary stored procedures, table variables, or cursors.
  • Internal objects that are created by the SQL Server Database Engine, for example, work tables to store intermediate results for spools or sorting.
  • Row versions that are generated by data modification transactions in a database that uses read-committed using row versioning isolation or snapshot isolation transactions.
  • Row versions that are generated by data modification transactions for features, such as: online index operations, Multiple Active Result Sets (MARS), and AFTER triggers.

Operations within tempdb are minimally logged. This enables transactions to be rolled back. tempdb is re-created every time SQL Server is started so that the system always starts with a clean copy of the database. Temporary tables and stored procedures are dropped automatically on disconnect, and no connections are active when the system is shut down. Therefore, there is never anything in tempdb to be saved from one session of SQL Server to another. Backup and restore operations are not allowed on tempdb.

Distribution

Database responsible for the replication metadata between the publisher and subscriber(s)

ReportServer

Primary database for Reporting Services to store the metadata and object definitions

  • Reports security
  • Job schedules and running jobs
  • Report notifications
  • Report execution history

ReportServer TempDB

Temporary storage for Reporting Services

Session information

Cache

Remote database support, DBAWorkDatabase support, Database services, Oracle ADF