Sunteți pe pagina 1din 11

1) Difference between Union & Union All ?

To combine the result sets of two or more queries and display all the rows returned by each of
the queries as one single result set

Differ -In Union All result appears twice.

Union Union All


Union remove duplicate rows (Performs In Union All result appears twice
distinct)
Due to above difference query execution time Fast Output with Duplicacy
of UNION ALL is smaller than UNION( Slow
OutPut)
Time consuming

2) Difference between union key and primary key?

Union Key Primary Key


Unique key in a table can be null primary key can not be null
primary key is a field or combination of fields primary key is a field or combination of fields
that uniquely identify a record in a table that uniquely identify a record in a table
Unique key is represented using unique while primary key is created using primary key
constraint constraint

UNIQUE KEY
PRIMARY KEY

NULL It doesn’t allow Null Allows Null value. But only one Null
values. value.
Because of this we
refer
PRIMARY KEY =
UNIQUE KEY + Not
Null CONSTRAINT

INDEX By default it adds a By default it adds a UNIQUE non-


clustered index clustered index

LIMIT A table can have A table can have more than one UNIQUE
only one PRIMARY Key Column[s]
KEY Column[s]

CREATE Below is the sample Below is the sample example for defining
SYNTAX example for defining a single column as a UNIQUE KEY column
a single column as a while creating a table:
PRIMARY KEY CREATE TABLE dbo.Customer
column while (
creating a table: Id INT NOT NULL UNIQUE,
CREATE FirstName VARCHAR(100),
TABLE dbo.Customer LastName VARCHAR(100),
( City VARCHAR(50)
Id INT NOT )
NULL PRIMARY KEY, Below is the Sample example for defining
FirstName VARCHAR multiple columns as UNIQUE KEY. It also
(100), shows how we can give name for the
LastName VARCHAR( UNIQUE KEY:
100), CREATE TABLE dbo.Customer
City VARCHAR(50) (
) Id INT NOT NULL,
Below is the Sample FirstName VARCHAR(100) NOT NULL,
example for defining LastName VARCHAR(100),
multiple columns as City VARCHAR(50),
PRIMARY KEY. It also CONSTRAINT UK_CUSTOMER UNIQUE(Id,
shows how we can FirstName)
give name for the )
PRIMARY KEY:
CREATE
TABLE dbo.Customer
(
Id INT NOT NULL,
FirstName VARCHAR
(100) NOT NULL,
LastName VARCHAR(
100),
City VARCHAR(50),
CONSTRAINT PK_CU
STOMER PRIMARY
KEY(Id,FirstName)
)
ALTER Below is the Syntax Below is the Syntax for adding UNIQUE
SYNTAX for adding PRIMARY KEY CONSTRAINT on a column when the
KEY CONSTRAINT on table is already created:
a column when the ALTER TABLE dbo.Customer
table is already ADD
created and doesn’t CONSTRAINT UK_CUSTOMER UNIQUE(Id)
have any primary
key:
ALTER
TABLE dbo.Customer
ADD
CONSTRAINT PK_CU
STOMER PRIMARY
KEY (Id)

DROP Below is the Syntax Below is the Syntax for dropping a


SYNTAX for dropping a UNIQUE KEY:
PRIMARY KEY: ALTER TABLE dbo.Customer
ALTER DROP CONSTRAINT UK_CUSTOMER
TABLE dbo.Customer
DROP
CONSTRAINT PK_CU
STOMER

3) Find out the second highest salary in the table ?


Select max(sal) from emp NOT IN (select max(sal) from emp
4) Difference between cluster & non cluster index ?
5) Types of Indexing ?

Index is created on a column in tables. It helps in providing fast access to data based on the values
stored in the column. Indexes are special lookup tables that the database search engine can use to speed
up data retrieval.

CREATE INDEX index_name ON table_name;

E.g.: If an index is created on primary key of a table and then search for a row based on primary key
value then SQL Server first finds that value in the index and then uses the index to locate the row in the
table instead of performing a complete table scan.

Types of indexes:

 Clustered: Stores the actual row at the leaf level of the index.
 Nonclustered: Stores only the values from the indexed column and row locators that point to the
actual row at leaf level instead of the actual row itself.
 Composite: Index containing more than one column (max 16).
 Unique: Ensures the uniqueness of each value in the indexed column.

6) Different type of Rank & Dens Rank ?


7)
8) Types of Joining ?

 INNER JOIN: Returns all rows when there is at least one match in BOTH tables
 LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
 RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
 FULL JOIN: Return all rows when there is a match in ONE of the tables
 Self Joining

9) Types of constraints?

SQL constraints are used to specify rules for the data in a table.
 If there is any violation between the constraint and the data action, the action is aborted by the
constraint.

Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the
table is created (inside the ALTER TABLE statement).

In SQL, we have the following constraints:

 NOT NULL - Indicates that a column cannot store NULL value


 UNIQUE - Ensures that each row for a column must have a unique value
 PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that
a column (or combination of two or more columns) have an unique
identity which helps to find a particular record in a table more easily and
quickly
 FOREIGN KEY - Ensure the referential integrity of the data in one table
to match values in another table
 CHECK - Ensures that the value in a column meets a specific condition
 DEFAULT - Specifies a default value when specified none for this column

10) What are the set operators?


a. SQL supports few Set operations to be performed on table data. These are used to get
meaningful results from data, under different special conditions.
i. Union - UNION is used to combine the results of two or more Select statements.
However it will eliminate duplicate rows from its result set. In case of union,
number of columns and datatype must be same in both the tables.
ii. Union All - This operation is similar to Union. But it also shows the duplicate
rows.
iii. Intersect - Intersect operation is used to combine two SELECT statements, but it
only returns the records which are common from both SELECT statements. In
case of Intersect the number of columns and datatype must be same. MySQL
does not support INTERSECT operator.
iv. Minus- Minus operation combines result of two Select statements and return
only those result which belongs to first set of result. MySQL does not support
INTERSECT operator.
11) Diff between delete & truncate ?

a. DELETE b. TRUNCATE
c. DELETE is a DML Command. TRUNCATE is a DDL command.
2. DELETE statement is executed using a 2. TRUNCATE TABLE always locks the
row lock, each row in the table is locked table and page but not each row.
for deletion. 3. Cannot use Where Condition.
3. We can specify filters in where clause 4. It Removes all the data.
4. It deletes specified data if where 5. TRUNCATE TABLE cannot activate a
condition exists. trigger because the operation does not
5. Delete activates a trigger because the log individual row deletions.
operation are logged individually. 6. Faster in performance wise, because it
6. Slower than truncate because, it keeps doesn't keep any logs.
logs. 7. Rollback is not possible.
7. Rollback is possible.
d. e.
f. g.
h. i.
j. k.
12) Diff between having & where clause ?
a. Both Having Clause and Where clause is used to filter the data coming from the Select
statement, but still there are some differences between them. These difference are
given below:-
i. 1) Where clause can be used with Select, Update and Delete Statement Clause
but having clause can be used only with Select statement.
ii. Where Clause is used on the individual records whereas Having Clause in
conjunction with Group By Clause work on the record sets ( group of records ).
iii. We can't use aggregate functions in the where clause unless it is in a subquery
contained in a HAVING clause whereas  we can use aggregate function in Having
clause. We can use column name in Having clause but the column must be
contained in the group by clause.
13) Diff between sub query & co-related sub query?
a.
14) How to delete duplicate record from the table ?
a.
15) What are the different type of normalization ?
16) What are the analytical functions?
17) What is composite key?
a. A composite key is a primary key that consists of more than one column. Oracle will create a
composite primary key index on the table to implement and enforce the composite key.
Composite keys are also known as concatenated or aggregate keys.

Example
18) For example, the LINE_ITEMS table may have a composite key on {orderID, itemNumber}:

19)CREATE TABLE line_items (


20) orderID NUMBER,
21) itemNumber NUMBER,
22) productId NUMBER,
23) quantity NUMBER,
24) PRIMARY KEY (orderID, itemNumber));

25) omposite primary key is a special type of primary key comprises a set of columns.In
relational database a primary key is a candidate key to uniquely identify each row in a
table.
A unique key or primary key comprises a single column or set of columns (COMPOSITE
Primary KEY).
No two distinct rows in a table can have the same value or combination of values(if it is
composite primary key) in those columns.
Primary keys are defined through the PRIMARY KEY constraint (ANSI SQL Standard).
The examples given below explains both Primary key and Composite primary keys.
The below given example uses CREATE TABLE statement to create a table with a single
column primary key.
26) ?

1 SQL> create table MYTABLE(

2 name VARCHAR2(50),

3 id NUMBER,

4 salary NUMBER(8,2),

5 CONSTRAINT MYTABLE_ID PRIMARY KEY (id));

6  

Table created
7

a.
27) Diff between view & materialized view ?
28) Advantage & disadvantage of views?
29) What is stored procedure & advantage of stored procedure?
30) Defined Trigger?
31) Difference between Row ID & Row number?
32) What are the aggregate functions?
a. Sum, max, min, average, count, last
33) What is Surrogated key?
34) List the different type of Join which support Ansi Standard SQL?
35) What are the different types of relationships between the table?
a. One to many, many to many, one to one
36) Find out top 5 salary?

SQL> select empno, ename, sal

  2  from emp

  3  where rownum <= 5

  4  order by sal;
a.
37) Difference between equi join & full outer join?
38) Difference between full outer & cartisian (cross) join?
a) Equi Join – Equi Joins are performed as name implies. Here we use = symbol. It is a
process of retrieving information from multiple tables using an equal to operator.
Select ename, eno, sal, dept, deptno from emp, dept where emp.deptno=
dept.deptno;
b) Cartesian Join – Cartesian product is combination of rows from diff table. No
where clause specified.
 Select ename, eno, sal, dept, deptno from emp, dept
c) NON –Equi Join – other than = operator if join is performed using any of operator
(<>, <=,>=)
d) Outer Join – it extends the result of eqi join . the symbol + represent outer
join.
 Left outer
 Right outer
e) Self joining – joining a table to itself is known as a self join. The self join can b
viewed as a join of two copies of the same table (actually two copies are not
created). To distinguish column names , aliases are used for the actual table.
39) NVL function ? (Null Value)
a. NVL function is used to substitute a NULL value in a query with an alternate value. 
SELECT NVL(commission, 0)
FROM sales;

This SQL statement would return 0 if the commission field contained a null value.


Otherwise, it would return the commission field.
b.
40) Find out 5th highest salry?
a.
41) Distinct function?
a. The SELECT DISTINCT statement is used to return only distinct (different) values.
b. The SQL DISTINCT keyword is used in conjunction with SELECT statement to
eliminate all the duplicate records and fetching only unique records.

Aliases vs. Context Comparison


Aliases Contexts
Resolves loop at design time Resolves loop when query is run
Creates more objects No additional objects added
1) Aliases cascade Context selection may be forced on user
2) Dimension object
3) A dimension object represents data that provides the basis for analysis in a
4) report. Dimension objects typically retrieve character-type data, for example;
5) customer names, resort names, or dates.
6) Dimension objects appear as follows in the Web Intelligence query panel:
7) Detail object
8) A detail obect provides descriptive data about a dimension. A detail is always
9) attached to the dimension for which it provides additional information. For
10) example, [Age] is a detail object that is associated with the (Customer]
11) dimension.

12) Detail objects appear as follows in the Web Intelligence query panel:
13) Working with queries in Web Intelligence Rich Client How universe objects map to data
14) Measure object
The measure object retrieves numeric data that is the result of calculations
on data in the database. For example, [Revenue] is the calculation of the
number of items sold multiplied by item price. Measure objects are often
located in a Measures class.
Measure objects appear as follows in the Web Intelligence query panel:
There are two types of measure:
• classic measures - calculated by Web Intelligence
• smart measures - calculated by the database on which the universe is
Based

15) Multiple queries, combined queries and synchronized queries


compared
It is important to understand the relationship between multiple data providers,
combined queries and synchronized data providers .
• A single data provider, or query, can contain multiple queries, called
combined queries.
• A document can be based on multiple data providers (each one of which
can contain multiple queries). These data providers do not need to be
synchronized. If they are not synchronized, the document contains multiple
sources of unrelated data.
• Multiple data providers can be synchronized if they have common
dimensions around which they can be linked. You synchronize data
providers by merging these common dimensions.

Controlling how queries retrieve data


Max retrieval time query property
Maximum time that a query can run before the query is stopped. This can
be useful when a query is taking too long due to an excess of data, or network
problems. You can set a time limit so a query can stop within a reasonable
time.
Max rows retrieved query property
The Max rows retrieved query property determines the maximum number
of rows of data that are displayed when a query is run. If you only need a
certain amount of data, you can set this value to limit the number of rows of
data in your document.
Max rows retrieved does not operate at the database level. If you set Max
rows retrieved to 1000, and your query returns 5000 rows, Web Intelligence
initially retrieves all 5000 rows, before discarding 4000 and retaining only
the first 1000 rows.
The Sample result set query property also applies a restriction on the
number of rows in the query, but at the database level. If you set Max rows
retrieved to 2000 and Sample result set to 1000, the query retrieves a
maximum of 1000 rows only.
This setting can be overridden by the limits set by your administrator in your
security profile. For example, if you set the Max rows retrieved setting to
400 rows, but your security profile limits you to 200 rows, only 200 rows of
data will be retrieved when you run the query.

LOOP - A loop is a join path issue that arises from the way that tables are related in a relational database.
Loops can produce instances where a query returns too few rows of data.

What is a derived table?


A derived table is a dynamic, virtual table that you create within the universe structure. It consists of
a set of SQL statements that you create in Universe Designer, and that you can then use as a logical
table to create objects.

Datawarehouse
A data warehouse is an enterprise wide centralized storage facility for different types of data. Data stored in
a data warehouse is characteristically subject oriented, time sensitive, and should be organized in a way that
allows data analysis. For example, a data warehouse can contain customer information and sales details per
customer, over the past five years
Some characteristics and features of data warehousing are as follows:
• Provides a consolidated storage of information from across the enterprise.
• Warehoused data is organized by subject area and is populated from many operational systems.
• Can act as a decision support system.
• Generally concerned with historical data and aggregates.
• Added to regularly, but loaded data is rarely ever directly changed.
• Regular schedule of dumps and loads from operational data stores.

Online Transactional Processing systems


Operational database systems deal with handling many users and transactions. These databases are
often referred to as Online Transactional Processing systems (or OLTP). These operational databases
are continuously used systems in which users add, update, and query the stored information.

OLTP systems have been designed to support the primary business processes and are optimized for
transaction processing. To avoid data redundancy and possible data conflicts the data model has been
normalized. An OLTP environment is not necessarily designed for querying and reporting, which can
potentially make universe design based on an OLTP a bit more challenging.

Data Marts
A data mart is a repository of data gathered from operational data or other sources and is designed
to serve a particular department or functional group. It is similar to a Data warehouse, but there
would be a difference in size and focus.

What causes a loop?


Answer: A loop is a join path issue that arises from the way that lookup and fact tables are related in
a relational database. Loops can produce instances where a query returns too few rows of data.

1. A chasm trap can occur when:


Answer:
1. Two joins from many-to-one-to-many converge on a single table.
2. The query includes objects based on the two “many” tables.
3. There are multiple rows returned for a single dimension value.
2. Describe two ways to resolve chasm traps.
Answer:
1. Create a context for each fact table. This solution works in all cases.
2. Modify the SQL parameters for the universe so you can generate separate SQL queries for each
measure. This solution only works for measure objects. It does not generate separate queries for
dimension or detail objects.
3. Describe three ways to resolve fan traps.
Answer:
1. Alter the SQL parameters for the universe. This only works for measure objects. This resolution
works the same for chasm and fan traps.
2. Create an alias for the table containing the initial aggregation, and then use Detect Contexts (Tools
> Detect Contexts) to detect and propose a context for the alias table and a context for the original
table. This is the most effective way to solve the fan trap problem as it will work with measure and
dimension objects.
3. Avoid the fan trap in the first place by using the same level of granularity.

1. What is a restriction?
Answer: A restriction is a condition in SQL that sets criteria to limit the data returned by a query.

1. What parameter does the @select require?


Answer: @select requires the path of the existing object to be dynamically linked to.
2. True or False. You can use the @where function in a condition object to point to an object, but not
the other way round.
Answer: True
3. What function is used to create an interactive object that causes a message to appear at query
runtime, that asks the user for specific input?
Answer:
b. @prompt

4. In the @prompt two parameters are mandatory and three are optional. What parameters are
optional?
Answer:
○ LOV pointer or hard-coded list
○ Mono or Multi
○ Free or Constrained

1. What part of the SQL expression does Designer use to create column names in the derived table?
Answer: It uses an alias (in SQL) to create column names.
For example: count(Region.Region_ID) as number_of_regions.
2. When you insert a derived table and insert joins, what happens if you do not add the new join to
the appropriate context?
Answer:
○ When you parse the derived table‟s SQL, it will generate an exception.
○ When you run a query, the derived table will create a Cartesian product.
○ The objects you create from the derived table will be incompatible with objects from any of the
existing contexts.
3. How do you apply index awareness on a universe object?
Answer: Go to the Keys tab of the Edit Properties dialog box for the object you want to make index
aware.
4. How can index awareness improve query performance?
Answer: It can improve query performance by taking advantage of indexes on key columns in the
data source.

BW

S-ar putea să vă placă și