Union Union All: Unique Key in A Table Can Be Null Primary Key Can Not Be Null
Union Union All: Unique Key in A Table Can Be Null Primary Key Can Not Be Null
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
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
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)
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.
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.
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).
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}:
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) ?
2 name VARCHAR2(50),
3 id NUMBER,
4 salary NUMBER(8,2),
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?
2 from emp
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;
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
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.
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.
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.
1. What is a restriction?
Answer: A restriction is a condition in SQL that sets criteria to limit the data returned by a query.
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