De-normalization is the process of attempting to optimize the performance of a database by adding
redundant data. It is sometimes necessary because current DBMSs implement the relational model
poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while
providing physical storage of data that is tuned for high performance. De-normalization is a technique
to move from higher to lower normal forms of database modeling in order to speed up database access.
Friday, April 18, 2008
What is De-normalization?
How to get @@error and @@rowcount at the same time?
If @@Rowcount is checked after Error checking statement then it will have 0 as the value of
@@Recordcount as it would have been reset.
And if @@Recordcount is checked before the error-checking statement then @@Error would get reset.
To get @@error and @@rowcount at the same time do both in same statement and store them in local
variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR
What is Identity?
Identity (or AutoNumber) is a column that automatically generates numeric values. A start and
increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers,
the value of this cannot be controled. Identity/GUID columns do not need to be indexed.
What is a Scheduled Jobs or What is a Scheduled Tasks?
Scheduled tasks let user automate processes that run on regular or predictable cycles. User can
schedule administrative tasks, such as cube processing, to run during times of slow business activity.
User can also determine the order in which tasks run by creating job steps within a SQL Server Agent
job. E.g. Back up database, Update Stats of Tables. Job steps give user control over flow of execution.
If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop
execution.
What is a table called, if it does not have neither Cluster nor Non-cluster Index? What is it
What is a table called, if it does not have neither Cluster nor Non-cluster Index? What is it
used for?
Ans:
Unindexed table or Heap. Microsoft Press Books and Book On Line (BOL) refers it as Heap.
A heap is a table that does not have a clustered index and, therefore, the pages are not linked by
pointers. The IAM pages are the only structures that link the pages in a table together.
Unindexed tables are good for fast storing of data. Many times it is better to drop all indexes from table
and than do bulk of inserts and to restore those indexes after that.
What is BCP? When does it used?
BulkCopy is a tool used to copy huge amount of data from tables and views. BCP does not copy the
structures same as source to destination.
How do you load large data to the SQL server database?
BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command helps to
Imports a data file into a database table or view in a user-specified format.
Can we rewrite subqueries into simple select statements or with joins?
Subqueries can often be re-written to use a standard outer join, resulting in faster performance. As we
may know, an outer join uses the plus sign (+) operator to tell the database to return all non-matching
rows with NULL values. Hence we combine the outer join with a NULL test in the WHERE clause to
reproduce the result set without using a sub-query
Can SQL Servers linked to other servers like Oracle?
SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to allow a link.
E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL
Server group.
How to know which index a table is using?
SELECT table_name,index_name FROM user_constraints
How to copy the tables, schema and views from one SQL server to another?
Microsoft SQL Server 2000 Data Transformation Services (DTS) is a set of graphical tools and
programmable objects that lets user extract, transform, and consolidate data from disparate sources
into single or multiple destinations.
What is Self Join?
This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self
join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it
involves a relationship with only one table. The common example is when company have a hierarchal
reporting structure whereby one member of staff reports to another.
What is Cross Join?
A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved
in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied
by the number of rows in the second table. The common example is when company wants to combine
each product with a pricing table to analyze each product at each price.
List few advantages of Stored Procedure.
· Stored procedure can reduced network traffic and latency, boosting application performance.
· Stored procedure execution plans can be reused, staying cached in SQL Server's memory,
reducing server overhead.
· Stored procedures help promote code reuse.
· Stored procedures can encapsulate logic. You can change stored procedure code without
affecting clients.
· Stored procedures provide better security to your data.
What is DataWarehousing?
· Subject-oriented, meaning that the data in the database is organized so that all the data
elements relating to the same real-world event or object are linked together;
· Time-variant, meaning that the changes to the data in the database are tracked and recorded
so that reports can be produced showing changes over time;
· Non-volatile, meaning that data in the database is never over-written or deleted, once
committed, the data is static, read-only, but retained for future reporting;
· Integrated, meaning that the database contains data from most or all of an organization's
operational applications, and that this data is made consistent.
What is OLTP(OnLine Transaction Processing)?
In OLTP - online transaction processing systems relational database design use the discipline of data
modeling and generally follow the Codd rules of data normalization in order to ensure absolute data
integrity. Using these rules complex information is broken down into its most simple structures (a table)
where all of the individual atomic level elements relate to each other and satisfy the normalization
rules.
How do SQL server 2000 and XML linked? Can XML be used to access data?
How do SQL server 2000 and XML linked? Can XML be used to access data?
FOR XML (ROW, AUTO, EXPLICIT)
Ans:
You can execute SQL queries against existing relational databases to return results as XML rather than
standard rowsets. These queries can be executed directly or from within stored procedures. To retrieve
XML results, use the FOR XML clause of the SELECT statement and specify an XML mode of RAW, AUTO,
or EXPLICIT.
OPENXML
OPENXML is a Transact-SQL keyword that provides a relational/rowset view over an in-memory XML
document. OPENXML is a rowset provider similar to a table or a view. OPENXML provides a way to
access XML data within the Transact-SQL context by transferring data from an XML document into the
relational tables. Thus, OPENXML allows you to manage an XML document and its interaction with the
relational environment.
What is an execution plan? When would you use it? How would you view the execution plan?
An execution plan is basically a road map that graphically or textually shows the data retrieval methods
chosen by the SQL Server query optimizer for a stored procedure or ad-hoc query and is a very useful
tool for a developer to understand the performance characteristics of a query or stored procedure since
the plan is the one that SQL Server will place in its cache and use to execute the stored procedure or
query. From within Query Analyzer is an option called "Show Execution Plan" (located on the Query
drop-down menu). If this option is turned on it will display query execution plan in separate window
when query is ran again.
Monday, April 7, 2008
Global Temporary Tables
I listened intently to the new Oracle programmer as he described all the struggles he's been having on his first big project. As I've done many times already in his short career, I interrupt with some words of wisdom.
"It's time to add Global Temporary Tables to your toolbelt."
"What are those?" he asks, as he opens the directory with the Oracle documentation. I smile. He has already learned where I always send him first.
"They're the ultimate work tables," I continue. "They're permanent tables, where you can add and modify session-specific data without affecting other sessions."
"What's so special about that?" he asks. "Even with regular tables, you can add and modify the data all you want without affecting other sessions. Just don't commit, and remember to rollback when your session is done."
"Oh yeah? And what about all the persistent work you're doing in your session? How do you commit that?"
"Oh yeah. Does it allow for indexes, and triggers, and views with regular tables?"
"Yep, all of that. See for yourself, it's easy. You've got the manual in front of you, so you drive."
Then I watched as he opened one session, and created a global temporary table.
SQL> CREATE GLOBAL TEMPORARY TABLE worktable (x NUMBER(3));
Table created.
He opened another session and was pleased to see the table there. He then added a row in the first session, committed it, and was planning to use the other session to see if the data was there. But instead he was in for a little surprise.
SQL> INSERT INTO worktable (x) VALUES (1);
1 row created.
SQL> SELECT * FROM worktable;
X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
no rows selected
"Hey!" he shouted. Heads popped up in nearby cubicles. "Where did it go?"
"Keep reading," I said, gesturing towards the "ON COMMIT" options for Global Temporary Tables. "By default, every time you commit your data, it is assumed that you want to clear out your work tables. Try PRESERVE."
He dropped the table, and tried again.
SQL> CREATE GLOBAL TEMPORARY TABLE worktable
2 (x NUMBER(3))
3 ON COMMIT PRESERVE ROWS;
Table created.
SQL> INSERT INTO worktable (x) VALUES (1);
1 row created.
SQL> SELECT * FROM worktable;
X
----------
1
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------
1
"That's better," he smiled. Now let's check the other session.
SQL> SELECT * FROM worktable;
no rows selected
"Excellent. So this data will remain there until my session ends?"
"Yep. Try it." He exited his session, logged back in, and sure enough the data was gone. "This is great. But what if I want to get rid of the data at some point in my session?"
"Truncate. Truncating the work table will only truncate the data in your session, not all the data."
"Hey neat. Thanks, this will be very useful. What are you doing for lunch later?"
"Aren't you even going to try it? What, you're just going to trust me?" I said. I think he was a little surprised that I would I'd rather talk about work tables than lunch. Frankly, so am I. Thankfully, he worked quickly, typing first in his second session.
SQL> INSERT INTO worktable (x) VALUES (2)
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT * FROM worktable;
X
----------
2
SQL> TRUNCATE TABLE worktable;
Table truncated.
SQL> SELECT * FROM worktable;
no rows selected
SQL> commit;
Commit complete.
"I don't think you need all those commits," I laughed. "But ok, now look back in your first session. If the row you added previously isn't there, then I'm a big fat liar. Otherwise, we can talk about lunch."
SQL> SELECT * FROM worktable;
X
----------
1
"So how about sushi?" he asked.
"Sushi?" I groaned. "Haven't you learned anything from me?"
Archives
-
▼
2008
(41)
-
▼
April
(21)
- What is De-normalization?
- How to get @@error and @@rowcount at the same time?
- What is Identity?
- What is a Scheduled Jobs or What is a Scheduled Ta...
- What is a table called, if it does not have neithe...
- What is BCP? When does it used?
- How do you load large data to the SQL server datab...
- Can we rewrite subqueries into simple select state...
- Can SQL Servers linked to other servers like Oracle?
- How to know which index a table is using?
- How to copy the tables, schema and views from one ...
- What is Self Join?
- What is Cross Join?
- Which virtual table does a trigger use?
- List few advantages of Stored Procedure.
- What is DataWarehousing?
- What is OLTP(OnLine Transaction Processing)?
- How do SQL server 2000 and XML linked? Can XML be ...
- OPENXML
- What is an execution plan? When would you use it? ...
- Global Temporary Tables
-
▼
April
(21)