Sunday, June 27, 2010

Cross-database foreign keys

What will be the output of the following scripts?

CREATE DATABASE db1;
CREATE DATABASE db2;
USE db1;
CREATE TABLE tb1
(
 AutoID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
 FKID INT NOT NULL
);
USE db2;
CREATE TABLE tb2
(
 AutoID INT NOT NULL PRIMARY KEY IDENTITY(1,1),
 FKID INT NOT NULL,
 FOREIGN KEY (FKID) REFERENCES db1.dbo.tb1(AutoID)
);
A. The scripts run successfully
B. Error occurs and mean that wrong referrer: db1.dbo.tb1
C. Error occurs and mean that cross database foreign key references are not supported
D. Error shows that wrong syntax when creating foreign key

Answer:[C]
Highlight to find out the answer.

Friday, June 25, 2010

#SQLServer #quiz

A support engineer reports that inserting new sales transactions in a SQL Server 2005 database results in an error. You investigate the error. You discover that in one of the databases, a developer has accidentally deleted some data in a table that is critical for transaction processing. The database uses the full recovery model. You need to restore the table. You need to achieve this goal without affecting the availability of other data in the database. What should you do?

A. Back up the current transaction log. Restore the database with a different name and stop at the point just before the data loss. Copy the table back into the original database.
B. Back up the current transaction log. Restore the database to the point just before the data loss.
C. Restore the database from the existing backup files to a time just before the data loss.
D. Restore the database to the point of the last full backup.

Answer:[A]
Highlight to find out the answer.

Tuesday, June 22, 2010

Oracle quiz

Rewrite the following IF statements so that you do not use the IF statement to set the value of no_revenue. What is the difference between the two statements?

IF total_sales <= 0 THEN
   no_revenue := TRUE;
ELSE
   no_revenue := FALSE;
END IF;

Answer:
no_revenue := NVL (total_sales, 1) <= 0;
Highlight to find out the answer.

Oracle Query