<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ramkarthick&#039;s Blog</title>
	<atom:link href="http://ramkarthick.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ramkarthick.wordpress.com</link>
	<description>Everything You Want in LIFE is waiting for you outside of your comfort &#34;ZONE&#34;</description>
	<lastBuildDate>Mon, 17 Oct 2011 10:03:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ramkarthick.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/272628528c66d0c0b8a3cc58e060bcdd?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Ramkarthick&#039;s Blog</title>
		<link>http://ramkarthick.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ramkarthick.wordpress.com/osd.xml" title="Ramkarthick&#039;s Blog" />
	<atom:link rel='hub' href='http://ramkarthick.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Top Five Reasons Data Warehouse Projects Fail</title>
		<link>http://ramkarthick.wordpress.com/2009/08/20/top-five-reasons-data-warehouse-projects-fail/</link>
		<comments>http://ramkarthick.wordpress.com/2009/08/20/top-five-reasons-data-warehouse-projects-fail/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 06:13:33 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[DWH]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=213</guid>
		<description><![CDATA[Too many data warehousing projects are failing in corporate America today.  Given the wealth of experience in the 1990’s and 2000’s, we are overlooking some fundamentals. Many factors play into why business intelligence initiatives fail in today’s corporate environment.  In the 1990’s, data warehousing methodology was still in it’s infancy.  The objectives were different.  Data integration and availability were the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=213&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Too many data warehousing projects are failing in corporate America today.  Given the wealth of experience in the 1990’s and 2000’s, we are overlooking some fundamentals.</p>
<p>Many factors play into why business intelligence initiatives fail in today’s corporate environment.  In the 1990’s, data warehousing methodology was still in it’s infancy.  The objectives were different.  Data integration and availability were the prime goals.  Selling the project was a matter of convincing management that data integration provides a more complete reporting picture for management.  ROI was measured on how much visibility KPIs and global statistics brought to the executives making decisions.  Project teams were allowed more time to develop reporting products.  Some projects that succeeded evolved into areas such as EAI.</p>
<p>In the 2000’s, corporate America became more sophisticated in the business intelligence arena.  Executives understood and often have seen the benefits of the data integration age.  KPIs are well developed.  Middle management began to depend on operational metrics measuring performance, profitability and the cost of managing their business areas.</p>
<p>Which brings us to the top five reasons data warehouse initiatives fail:</p>
<ol>
<li><strong>Biting off too big a bite</strong>.  Projects that scope work in the big bang approach are doomed for failure.  Project teams usually find success by scoping the project into many smaller increments, giving three to five months to deliver.</li>
<li><strong>Competing projects</strong>.  Warehouse projects are expensive to begin and require a unified effort to provide true integration.  Multiple projects with data integration as the goal will guarantee your project (if it is allowed to continue) will be just another data silo consuming corporate resources.</li>
<li><strong>Lack of corporate vision</strong>.  Most companies are very focused on how to deliver products and services.  Global reporting requires the same diligence in developing an data integration strategy.  Key performance indicators (KPIs) used to drive business decision requires coordination across the business.  A clear, concise vision of what the corporation will look like will help drive clear goals and objectives.</li>
<li><strong>Dirty data</strong>.  Data integration brought out the ugly side of what’s been going on at the lowest levels.  Reports that are produce incomplete or inaccurate results will hurt the initiative.  The need for data governance and business stewardship is the answer.</li>
<li><strong>Insufficient technical design</strong>.  Reporting initiatives are more often victims of cost-cutting, econo-designs.  Look carefully at server capacity and dedicate services whenever possible.  Separate the Stage environment from the ODS and Fact area.  This will expand bandwidth and allow modularization of key processes.  Allow plenty of resources for persistent areas, even Staging.  Separate reporting and ETL load functions into different application server environments.  Look at this also for the database schemas as well.  The extra cost and planning will allow for faster processing and happier customers.</li>
</ol>
<p>More is expected from IT today.  And with less.  It is critical to get some wins for the business and executives early in the initiative.  Everyone understands the promise of data warehousing, it is our job to execute and capitalize on that promise.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=213&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/08/20/top-five-reasons-data-warehouse-projects-fail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>
	</item>
		<item>
		<title>Five Steps to More Valuable Enterprise Data</title>
		<link>http://ramkarthick.wordpress.com/2009/05/21/five-steps-to-more-valuable-enterprise-data/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/21/five-steps-to-more-valuable-enterprise-data/#comments</comments>
		<pubDate>Thu, 21 May 2009 09:02:34 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[DWH]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=206</guid>
		<description><![CDATA[Introduction Every  good  business decision is based upon  good  data. Whether making operational, analytical or strategic decisions, every department in an organization from  the boardroom to the sales floor requires reliable, accurate information — from  knowing which customers own what products, to knowing which customers are  potential opportunities for up-sell — to make those decisions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=206&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><a href="http://ramkarthick.files.wordpress.com/2009/05/data.jpg"><img class="aligncenter size-full wp-image-207" title="Data" src="http://ramkarthick.files.wordpress.com/2009/05/data.jpg?w=500&#038;h=420" alt="Data" width="500" height="420" /></a></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong><br />
</strong></span><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Introduction</strong></span></p>
<p style="text-align:justify;"><span style="color:#003366;"><strong></strong></span></p>
<p style="text-align:justify;">Every  good  business decision is based upon  good  data. Whether making operational, analytical or strategic decisions, every department in an organization from  the boardroom to the sales floor requires reliable, accurate information — from  knowing which customers own what products, to knowing which customers are  potential opportunities for up-sell — to make those decisions correctly. But it&#8217;s also  true that bad  data inevitably leads to bad business decisions, improper strategies and  poor  customer service.</p>
<p style="text-align:justify;">As companies undertake data-dependent initiatives, such as enterprise resource planning (ERP), customer relationship management (CRM) or enterprise initiatives leading to complete data governance, it is important to remember that data quality issues exist in any  organization. Successfully addressing these data quality issues — and  establishing the controls to maintain the quality of that data — is critical to the success of any of these initiatives.</p>
<p style="text-align:justify;">There are  many reasons for the explosion of inconsistent or unusable data, from  simple human error to the lack of data standards across systems, business units or divisions. To overcome the problems of bad  data, organizations need to create a technological foundation for finding  and  eliminating data quality problems.</p>
<p style="text-align:justify;">But data quality issues cannot be resolved by technology alone. Having  the correct people and  processes in place is also  crucial. This paper will show  how a five-phase process can successfully organize people, processes and  technology in a proven data quality methodology that allows  organizations to analyze, improve and  control corporate data.</p>
<p style="text-align:justify;">The Five Steps to More Valuable Enterprise Data Technology is only part of the solution to produce consolidated, high-quality corporate information. While it&#8217;s essential to have robust technology supporting any data quality initiative, having an appropriate methodology for using that technology will be even more essential to the success of the initiative.</p>
<p style="text-align:justify;">DataFlux has developed a five-component methodology for enterprise data quality and data governance based on over a decade of experience and  thousands of implementations. The five components are  data profiling, data quality, data integration, data enrichment and  data monitoring. Together, these five steps provide a proven, practical approach to data governance that allows  organizations to analyze, improve and control their data.</p>
<p style="text-align:justify;"><a href="http://ramkarthick.files.wordpress.com/2009/05/new-picture.png"><img class="aligncenter size-full wp-image-208" title="New Picture" src="http://ramkarthick.files.wordpress.com/2009/05/new-picture.png?w=500" alt="New Picture"   /></a></p>
<p style="text-align:justify;">
<p style="text-align:justify;">These components provide a framework for the successful management of the entire data improvement process. When followed, this methodology results in a unified view of any type of data, including customer, product and  supplier information anywhere in the enterprise.</p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Data  Profiling</strong></span></p>
<p style="text-align:justify;">The first step in the process, data profiling is the examination of the structure, relationships and  content of existing data sources to help  create an accurate picture of the state of the data. By determining the current state of the data, data profiling helps in planning the best ways  to correct or reconcile information assets.</p>
<p style="text-align:justify;">There are  three separate components of a data profiling exercise, each of which analyzes data in a unique way, that together create a clear picture of the nature and  scope of data quality issues.</p>
<p style="text-align:justify;">Data  profiling is essentially the process of addressing key questions about the data for each of these components:</p>
<ul style="text-align:justify;">
<li>Structure discovery – Do the data patterns match expected patterns? Does  the data match the corresponding metadata?</li>
</ul>
<ul style="text-align:justify;">
<li>Data  discovery – Are the data values complete, accurate and  unambiguous? Is the data standardized according to established conventions?</li>
</ul>
<ul style="text-align:justify;">
<li>Relationship discovery – Does the data adhere to specified required key relationships across columns and  tables? Are there inferred relationships across columns, tables or databases? Is there redundant data?</li>
</ul>
<p style="text-align:justify;">Figure 2 shows the type of report generated during data profiling efforts. This analysis is an example of data discovery, as it shows the number of null counts for different fields within  the database.  Note that the overall count of 5000 records is consistent, but some fields  show  a high number of null values. With an understanding that there are  significant percentages of missing values in several key fields  - ADDRESS, CITY, STATE, and particularly GENDER – business analysts can  be immediately aware of the scope and nature of data quality issues.</p>
<p style="text-align:justify;">
<p style="text-align:justify;"><a href="http://ramkarthick.files.wordpress.com/2009/05/new-picture1.png"><img class="aligncenter size-full wp-image-209" title="New Picture" src="http://ramkarthick.files.wordpress.com/2009/05/new-picture1.png?w=500&#038;h=293" alt="New Picture" width="500" height="293" /></a></p>
<p style="text-align:justify;">Profiling provides quantifiable information detailing the strengths and  weaknesses of corporate data. This knowledge can  be used as the basis for subsequent data improvement. The information gained from  data profiling feeds the next phase &#8211; data quality.</p>
<p style="text-align:justify;"><strong><span style="color:#003366;">Data  Quality</span></strong></p>
<p style="text-align:justify;">The data quality phase applies the knowledge gained during data profiling to begin  the process of building better data. This phase helps correct errors, standardize information, and  validate data throughout the enterprise.</p>
<p style="text-align:justify;">There are  a number of different tactics employed during this  phase. Some of the most commonly employed measures include:</p>
<ul style="text-align:justify;">
<li>Data  standardization to address and  correct multiple permutations of data. For example, ACME Manufacturing Corporation may  be represented in the same data source as Acme  Mftg Corp, ACME and  ACME Manufacturing. Intelligent fuzzy matching allows  these variants to be standardized to create a single nomenclature.</li>
</ul>
<ul style="text-align:justify;">
<li>Pattern standardization to create valid patterns of data across tables and columns. Some pieces of data, such as phone numbers or Social  Security</li>
</ul>
<p style="text-align:justify;">Numbers, are  found  in easily recognized variant patterns. Others, such as product or item data, may  have different standards across industries or companies. Pattern standardization can  take information in non-standard formats and transform it into  an accepted standard format.</p>
<ul style="text-align:justify;">
<li>Address verification to confirm that addresses are  valid and  actionable. For example, DataFlux software can  determine if the city  and  state do not match the ZIP code. The software searches postal data, locates the proper ZIP code and changes it to create an accurate address.</li>
</ul>
<p style="text-align:justify;">Figure 3 shows how technology can  help create a step-by-step business rules to address data quality problems. In this example, the workflow  starts with the source table, then progresses through standardization, address verification and  other routines. The earlier data profiling routine uncovered these issues, and  the user creates steps to address each identified problem.</p>
<p style="text-align:justify;"><a href="http://ramkarthick.files.wordpress.com/2009/05/new-picture-1.png"><img class="aligncenter size-full wp-image-210" title="New Picture (1)" src="http://ramkarthick.files.wordpress.com/2009/05/new-picture-1.png?w=500" alt="New Picture (1)"   /></a></p>
<p style="text-align:justify;">The specific approach taken may  differ for each data element, and  the decision on the approach falls to the business area responsible for the data.</p>
<p style="text-align:justify;">It is also  important to note that the data quality activity improves the existing data but does not address the root cause of the data problems. If the enterprise is truly interested in improving data quality, it must also  investigate the reasons that the data contained errors and  initiate appropriate actions, including incentives and  changes to business procedures to improve future data.</p>
<p style="text-align:justify;">With data quality complete, organizations have enacted the measures to bring  the completeness and  accuracy of the data in each source to acceptable levels. The next step is integration from  multiple sources.</p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Data  Integration</strong></span></p>
<p style="text-align:justify;">For any type of data, different data elements about the same item will often exist in multiple databases. Data integration is useful when  organizations attempt to rationalize data across different sources. Data  integration provides the ability to take these divergent pieces of information and  unify them within  a single master record.</p>
<p style="text-align:justify;">For example, a company has two product files: a master product extracted from  its USA- based enterprise resource planning (ERP) package and  a product database from  Europe. The company sells the same products in both areas, but the products are listed in each database by different names. In addition, the product, brand and  descriptions in each file had  been input by different data entry personnel.</p>
<p style="text-align:justify;">The first challenge in data integration is to recognize that the same product exists in each of the two sources &#8211; the process of linking — and  the second challenge is to combine the data into a single view of the product — the process of consolidation.</p>
<p style="text-align:justify;">With customer data, there is often a common field, such as a tax identification number, that can  help identify commonality. When this  occurs, companies can  identify multiple records for the same customer quickly  and  easily.</p>
<p style="text-align:justify;">With product data, this  is often not the case. In the earlier example, data integration technology enabled the company to identify the product information for linking across the two different systems and  consolidate the data.</p>
<p style="text-align:justify;">Intelligent fuzzy matching identified a product description that was  common to both files. The USA file contained the description, brand name and  product identifier all in one  field and  in various patterns. The European file contained only product descriptions, also  with varied patterns and  abbreviations. To uncover the connection, data integration technology was used to:</p>
<ul style="text-align:justify;">
<li>Parse the description from  the USA file into product specific attributes and into a brand name</li>
</ul>
<ul style="text-align:justify;">
<li>Reconcile the differences in brand names</li>
</ul>
<ul style="text-align:justify;">
<li>Reconcile the differences in product attributes (short forms, abbreviations, etc.)</li>
</ul>
<ul style="text-align:justify;">
<li>Phonetically match the reconciled data</li>
</ul>
<ul style="text-align:justify;">
<li>Display  reports of matching products</li>
</ul>
<p style="text-align:justify;">After data integration, the company now possessed a comprehensive view of all the data know about a subject. The same principles and  techniques may  be applied to any  type of data to create integrated master records.</p>
<p style="text-align:justify;">The next step is to increase the data’s value by enhancing it with additional information.</p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Data  Enrichment</strong></span></p>
<p style="text-align:justify;">Data  enrichment entails incorporating additional external data to add  value to existing records. There are  multiple ways  this  may  occur. Data enrichment may  mean enhancing corporate data with third-party data to increase an understanding of the customer and their buying potential and  loyalty. Or, advanced geocoding to add  enriched geographic information — such as being  able  to know that all the houses in a particular ZIP-code-plus- 4 area were built  after 1980 and  exceed a certain property value — provides information to target certain product offerings.</p>
<p style="text-align:justify;">An understanding of the behavior of customers can  also  be attained with analysis of certain attributes. By combining that data with specific customer data, one  could  segment customers more effectively to identify specific opportunities.</p>
<p style="text-align:justify;">Figure 4 illustrates how data improvement technology can  add  crucial components to a regular street address by matching the submitted record to external data sources.</p>
<p style="text-align:justify;">
<p style="text-align:justify;"><a href="http://ramkarthick.files.wordpress.com/2009/05/new-picture-2.png"><img class="aligncenter size-full wp-image-211" title="New Picture (2)" src="http://ramkarthick.files.wordpress.com/2009/05/new-picture-2.png?w=500&#038;h=372" alt="New Picture (2)" width="500" height="372" /></a></p>
<p style="text-align:justify;">Data  enrichment can  be used for more than just  address data. Many types of data, including product, inventory and  financial data, can  have value added by connecting the data to external sources.</p>
<p style="text-align:justify;">This can  mean appending industry-standard product codes from  registries like UNSPSC or <a href="mailto:eCl@ss">eCl@ss</a> to standardize product or inventory records and  streamline buying and  selling goods. Integrating your  database with these universal codes can  guarantee the correctness of inventory, increase efficiency in ordering and  help pave the way for smooth international operations.</p>
<p style="text-align:justify;">Data  enrichment also  helps manage corporate compliance issues, by comparing customer lists or transactions to external lists in accordance with government or industry regulations. This can  be used to conduct anti-money laundering checks, enact fraud detection or integrate do-not-call registries.</p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Data  Monitoring</strong></span></p>
<p style="text-align:justify;">Data  monitoring is essential to a complete data governance program, ensuring that hard- won data improvement end  enrichment efforts aren&#8217;t degraded by the creeping return of data errors. Active data monitoring can  help  companies understand the condition of their data, and  to isolate and  correct the causes of data quality issues.</p>
<p style="text-align:justify;">Data  monitoring can  take a number of forms. The simplest version of data monitoring automates a profiling report &#8211; a periodic analysis of the data that searches for exceptions and  non-standard data &#8211; trigger events, such as too  great a percentage of exceptional data, would generate an email  or a system alert to the individuals or department responsible for the data.</p>
<p style="text-align:justify;">Another, more dynamic &#8211; and  more effective &#8211; method of data monitoring is to actively enforce business rules as web services. Using this  method, the same rules which were used to cleanse and  enhance the data can  be applied to data in real  time  as it enters and moves through the enterprise. The advantages of this  approach include the ability to:</p>
<ul style="text-align:justify;">
<li>Enforce data governance rules – Ensure business-specific rules for how organizational data should be managed and  handled are  followed.</li>
</ul>
<ul style="text-align:justify;">
<li>Understand and  refine mission-critical processes – Violations or exceptions to business rules are  logged in a repository, to track and  address trends.</li>
</ul>
<ul style="text-align:justify;">
<li>Invoke  events to correct the data – The monitoring engine can  invoke  events to automatically correct data, email  business users, log the data to the</li>
</ul>
<p style="text-align:justify;">repository, or simply  write the data to a database table.</p>
<p style="text-align:justify;"><span style="color:#003366;"><strong>Summary</strong></span></p>
<p style="text-align:justify;">The quality of any  business analysis is only as good  as the data at its foundation. Without data that is consistent, accurate and  reliable across the enterprise, an organization can easily reach misleading, faulty and  potentially harmful conclusions.</p>
<p style="text-align:justify;">An organization’s success in data analysis begins with finding  a methodology and  solution that encompasses each of these building  blocks – data profiling, data quality, data integration, data enrichment and  data monitoring.</p>
<p style="text-align:justify;">Today’s powerful new data quality and  data integration technology allows  organizations to support data-driven initiatives on an unprecedented level,  providing a unified view of customer, product, supplier and  other data assets on a wide variety of applications across the enterprise.</p>
<p style="text-align:justify;">Through the combination of an intelligent methodology and  appropriate technology, an organization can  elevate the role  of data quality to an ongoing corporate activity, enabling better business decisions and  competitive advantage, all based on high-quality information.</p>
<p style="text-align:justify;">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=206&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/21/five-steps-to-more-valuable-enterprise-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/data.jpg" medium="image">
			<media:title type="html">Data</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/new-picture.png" medium="image">
			<media:title type="html">New Picture</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/new-picture1.png" medium="image">
			<media:title type="html">New Picture</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/new-picture-1.png" medium="image">
			<media:title type="html">New Picture (1)</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/new-picture-2.png" medium="image">
			<media:title type="html">New Picture (2)</media:title>
		</media:content>
	</item>
		<item>
		<title>MindSet</title>
		<link>http://ramkarthick.wordpress.com/2009/05/13/mindset/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/13/mindset/#comments</comments>
		<pubDate>Wed, 13 May 2009 11:24:14 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/2009/05/13/mindset/</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=188&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><a href="http://ramkarthick.files.wordpress.com/2009/05/noname.jpg"><img class="size-full wp-image-187 aligncenter" title="noname" src="http://ramkarthick.files.wordpress.com/2009/05/noname.jpg?w=500&#038;h=373" alt="noname" width="500" height="373" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=188&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/13/mindset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/noname.jpg" medium="image">
			<media:title type="html">noname</media:title>
		</media:content>
	</item>
		<item>
		<title>Trends in Business Intelligence</title>
		<link>http://ramkarthick.wordpress.com/2009/05/07/trends-in-business-intelligence/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/07/trends-in-business-intelligence/#comments</comments>
		<pubDate>Thu, 07 May 2009 12:49:29 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=181</guid>
		<description><![CDATA[Peter Thomas ( Business Intelligence and Cultural transformational Experts) View: I would like to share his information for others benefit.. Enjoy&#8230; This year, as in every year since the phrase “Business Intelligence” first came to prominence, there have been a rash of predictions about what will happen with the area in 2009. I have linked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=181&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><img class="aligncenter size-full wp-image-180" title="trends" src="http://ramkarthick.files.wordpress.com/2009/05/trends.jpg?w=500" alt="trends"   /></p>
<p style="text-align:justify;">Peter Thomas ( Business Intelligence and Cultural transformational Experts) View: I would like to share his information for others benefit.. Enjoy&#8230;</p>
<p style="text-align:justify;">This year, as in every year since the phrase “Business Intelligence” first came to prominence, there have been a rash of predictions about what will happen with the area in 2009. I have linked to and commented on some of these myself on this blog. This article is my take on the area. I should however explain that there is a twist. These are not the trends that I expect to see in 2009, just my thoughts on what ought to be trends in BI over the next few years. I cannot claim to have any prescience about whether they will come to pass, but I will be encouraged if they do.</p>
<ol style="text-align:justify;">
<li>A more      holistic approach to BI in organisations that have already invested</li>
<li>Operational      BI</li>
<li>Consolidation      of the number of BI platforms with organisations</li>
<li>An      increase in the prevalence of BI competency centres</li>
<li>BI teams      being jointly owned and managed by business divisions and IT</li>
<li>Data      from central warehouses being served to front-end applications</li>
<li>BI data      being used to automate some business decisions</li>
<li>Further      emphasis on predictive analytics</li>
<li>BI      having an increasing role in compliance and risk management</li>
<li>Incorporation      of external data into BI platforms</li>
<li>Provision      of BI to business partners and/or customers</li>
<li>The most      creative users of BI employing it to thrive, even in the current climate</li>
</ol>
<p style="text-align:justify;"><strong>1. A more holistic approach to BI in organizations that have already invested</strong></p>
<p style="text-align:justify;">Often BI solutions have started in a single area. Typically – given its direct link to better managing overall performance – this has been around analysing an organisation’s financial results, though implementations starting in the sales and even operational arenas are also not uncommon. BI systems tend to add more value as they bring in more information, particularly where a high-level phenomenon – e.g. a decrease in expenditure – can be attributed to lower level ones – e.g. greater repeat business (business acquisition being more expensive than repeat business in most industries), plus enhanced productivity, plus reduced staff turnover (resulting in lower recruitment and training costs). To do this, BI needs to widen its scope to take on new data sources and combine them in creative ways. Where BI platforms have already added value, there will be pressure from users to expand them to deliver even more utility and provide more sophisticated insights. This in turn will require BI practitioners to take a more holistic view of the area and to develop roadmaps explaining how new data sources will be brought on stream and what business value will result from this.</p>
<p style="text-align:justify;"><strong>2. Operational BI</strong></p>
<p style="text-align:justify;">I think that there is a particular argument for BI to make a greater contribution in the area of operational management, particularly tying this to overall performance. Often BI implementations have focussed on the more stately world of monthly (or weekly) results and steered clear of the daily or hourly demands of operational information. The BI projects that I have seen in the Operational sphere have been more focussed at producing weekly status reports or year-to-date trend analyses. Related to BI platforms expanding to new areas, I see increasing demand for information about the internal effectiveness of an organisation; quickly identifying bottlenecks or areas of inefficiency and tracking efforts to address these. Supporting this type of reporting will often require BI practitioners to rethink their architectures which are often set up to refresh on longer timeframes. This may in turn require the warehouse to support multiple environments with different periodicities.</p>
<p style="text-align:justify;"><strong>3. Consolidation of the number of BI platforms with organisations</strong></p>
<p style="text-align:justify;">It is all too common for organisations to have separate BI implementations. Maybe the ERP system comes with some shrink-wrapped cubes, as does the CRM system. Perhaps Finance have invested in some budget analysis tools and different business units have started dabbling in predictive modelling (see 8. below). Maybe certain power users or numerate departments have their own, much cherished databases. Clearly this approach is sub-optimal. If it was ever acceptable to have such an ad hoc approach to the area, the current economic climate means that there is no longer room for a multitude of platforms, each supported by their own ETL, servers, IT teams and (hopefully) training programmes. While transitional costs may make it impractical for some organisations to move to a single platform in the short term, the reductions in licensing, internal support, data centre and training costs that come from standardising BI tools are compelling. This is to say nothing about reducing the level of confusion in users faced with multiple reporting and analysis systems, each with their own terminology, vagaries of functionality and often un-reconciled to each other. Arguments about certain BI tools being best of breed for particular tasks were never wholly convincing, with the breadth of functionality offered by all of the major players today, any of them will be at least good enough for all but the most exacting of applications.</p>
<p style="text-align:justify;"><strong>4. An increase in the prevalence of BI competency centres</strong></p>
<p style="text-align:justify;">If this is partly as a result of the previous three trends, it also has some drivers all of its own. Even in multinational organisations with highly devolved structures and local accountability, most of the management information that is needed to run businesses will be relatively consistent from country to country and business unit to business unit. Perhaps the sources will vary, but the business transactions that they support are surprisingly consistent. Many organisations are waking up to this fact and pulling BI provision into the centre. There are obvious benefits to this in terms of cost savings, not reinventing the wheel, increasing the consistency of reporting and enabling corporate roll-ups. However, my own feeling is that the best organisations will supplement a strong central resource with a (probably much smaller) virtual component located close to business needs who can better respond to these in a timely manner, but within an overall information architecture. This hybrid approach offers the best of both worlds.</p>
<p style="text-align:justify;"><strong>5. BI teams being jointly owned and managed by business divisions and IT</strong></p>
<p style="text-align:justify;">It is an oft-repeated aphorism that all IT projects are business projects. While clearly true in theory, there are enough counterexamples to suggest that practise is rather different. However, BI projects have often stayed much closer to this maxim than other IT efforts. This is because BI systems serve no purpose unless they are closely entwined with business goals. Natural selection should weed out any non-business-focussed BI projects eventually; even in the sleepiest of organisations. It is likely that this close relationship will deepen. Whilst many aspects of BI are firmly in the IT arena (managing the regular refresh of multiple terabytes of data effectively clearly being one), I see a joint stewardship of the area developing. By this I mean something deeper than business oversight or steering committees. It is also different to business BI liaison managers being appointed – these roles often have the unintended consequence of isolating IT from its customers. What I see emerging in more enlightened organisations is true co-ownership of BI with business and IT management closely collaborating to run the area.</p>
<p style="text-align:justify;"><strong>6. Data from central warehouses being served to front-end applications</strong></p>
<p style="text-align:justify;">Of course it is not uncommon for transaction processing systems to have buttons or links that call up a given report. What I am talking about here is a closer coupling, one that does not require users to leave their current system and where information from the warehouse is presented in a seamless manner to users. While such information will have all the BI benefits of being reconciled, consistent and accurate, its provenance will increasingly become invisible to the user (who shouldn’t really have to worry where figures come from so long as they are accurate). This is an area in which web-services have some real potential to leverage the investments that organisations have made in warehouses.</p>
<p style="text-align:justify;"><strong>7. BI data being used to automate some business decisions</strong></p>
<p style="text-align:justify;">Stepping a little further along the path from the previous point, even before users of front-end systems have a need to review information about a transaction, it may well be that the information itself has been what determines whether a human is involved or not. Already some organisations perform triage on business transactions. Ones that meet all of a number of requirements get processed automatically. Ones that meet some of them, but not all, may get routed to junior staff, whose role is to determine whether they require further review or can proceed. Finally, those with a major variance to requirements may get sent straight to more senior staff. This approach means that a larger volume of business can be handled and that expensive senior resource is only applied where it is necessary. Of course a prerequisite to this type of approach is having reliable information on which to perform the triage.</p>
<p style="text-align:justify;"><strong>8. Further emphasis on predictive analytics</strong></p>
<p style="text-align:justify;">While the best BI implementations encourage users to extrapolate from past figures to estimate future ones, the degree to which the analytical skills of the user plays a part varies from implementation to implementation. Here by analytics I mean the use of larger data sets to identify trends or exceptions, mostly at a portfolio level. Again, having invested in developing data warehouses, it makes sense to utilise the many and sophisticated tools that are available to carry out advanced statistical analysis on these; the aim being to deduce trends that would be beyond even the most skilled of human analysts. A by-product of successful BI implementations is that they often free the more numerate of people in organisations from the burden of repetitive number crunching and allow them to focus on more added-value work such as this.</p>
<p style="text-align:justify;"><strong>9. BI having an increasing role in compliance and risk management</strong></p>
<p style="text-align:justify;">Sometimes BI projects may have had their genesis in these areas. However, even when this is not the case a pleasing result of having consolidated much of the organisation’s data in one place is that this then forms a valuable resource for compliance and risk management. Indeed, taking an external perspective, regulators tend to view the existence of an enterprise data warehouse as a sign that an organisation takes managing its risks seriously. Although business managers and risk managers may have slightly different (though hopefully complementary) perspectives and want to answer different types of questions, the data that they need to do this is not that dissimilar. Producing compliance suites from a well-designed warehouse is probably not one of the more taxing BI problems. Again expansion in this area is a further example of point 1. in action.</p>
<p style="text-align:justify;"><strong>10. Incorporation of external data into BI platforms</strong></p>
<p style="text-align:justify;">I have spoken above about the remit of BI systems expanding internally and becoming more consistent geographically. A further trend in expansion is to meld internal information with that from external providers. The type of external information would range from industry to industry, but might include market data, information about specific companies or individuals (e.g. credit scores, where the use of these is admissible). For example, in insurance, where I have spent the last twelve years of my career, incorporating information from externally produced flood, or windstorm models is often a priority.</p>
<p style="text-align:justify;"><strong>11. Provision of BI to business partners and/or customers</strong></p>
<p style="text-align:justify;">Sometimes one objective of BI implementations is to better understand the relationships with business partners and customers. I have seen this develop to the degree where output from BI systems is mailed to such counterparties. A logical extension of this is to allow such organisations direct access to “their information”. Of course as with any e-commerce initiative, there would have be to strict controls on what is viewed and who can view it, but these are problems that are regularly addressed in other areas of IT and the tools to do this are readily available.</p>
<p style="text-align:justify;"><strong>12. The most creative users of BI employing it to thrive, even in the current climate</strong></p>
<p style="text-align:justify;">There have been many articles which have spoken about good BI being a great defence in times of economic stress. I would go beyond this and state that the real BI pioneers will take advantage of these capabilities to capture markets from their less well-informed competitors and to steer a course away from areas of business that may bring other less-foresighted organisations down. I look forward to seeing case studies bearing this out appear over the next few years.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=181&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/07/trends-in-business-intelligence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/trends.jpg" medium="image">
			<media:title type="html">trends</media:title>
		</media:content>
	</item>
		<item>
		<title>Learn SQL Queries</title>
		<link>http://ramkarthick.wordpress.com/2009/05/07/learn-sql-queries/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/07/learn-sql-queries/#comments</comments>
		<pubDate>Thu, 07 May 2009 12:18:41 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=167</guid>
		<description><![CDATA[SQL is a standard language for accessing and manipulating databases. What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases SQL is an ANSI (American National Standards Institute) standard What Can SQL do? SQL can execute queries against a database SQL can retrieve data from a database SQL can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=167&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>SQL is a standard language for accessing and manipulating databases.</strong></p>
<hr size="1" noshade="noshade" /><strong>What is SQL?</strong></p>
<ul type="disc">
<li>SQL stands for      Structured Query Language</li>
<li>SQL lets you      access and manipulate databases</li>
<li>SQL is an ANSI      (American National Standards Institute) standard</li>
</ul>
<hr size="1" noshade="noshade" /><strong>What Can SQL do?</strong></p>
<ul type="disc">
<li>SQL can execute      queries against a database</li>
<li>SQL can retrieve      data from a database</li>
<li>SQL can insert      records in a database</li>
<li>SQL can update      records in a database</li>
<li>SQL can delete      records from a database</li>
<li>SQL can create      new databases</li>
<li>SQL can create      new tables in a database</li>
<li>SQL can create      stored procedures in a database</li>
<li>SQL can create      views in a database</li>
<li>SQL can set      permissions on tables, procedures, and views</li>
</ul>
<hr size="1" noshade="noshade" /><strong>SQL is a Standard &#8211; BUT&#8230;.</strong></p>
<p>Although SQL is an ANSI (American National Standards Institute) standard, there are many different versions of the SQL language.</p>
<p>However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.</p>
<p><strong>Note:</strong> Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!</p>
<hr size="1" noshade="noshade" /><strong>Using SQL in Your Web Site</strong></p>
<p>To build a web site that shows some data from a database, you will need the following:</p>
<ul type="disc">
<li>An RDBMS database      program (i.e. MS Access, SQL Server, MySQL)</li>
<li>A server-side      scripting language, like PHP or ASP</li>
<li>SQL</li>
<li>HTML / CSS</li>
</ul>
<hr size="1" noshade="noshade" /><strong>RDBMS</strong></p>
<p>RDBMS stands for Relational Database Management System.</p>
<p>RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.</p>
<p>The data in RDBMS is stored in database objects called tables.</p>
<p>A table is a collections of related data entries and it consists of columns and rows.</p>
<p><strong>Database Tables</strong></p>
<p>A database most often contains one or more tables. Each table is identified by a name (e.g. &#8220;Customers&#8221; or &#8220;Orders&#8221;). Tables contain records (rows) with data.</p>
<p>Below is an example of a table called &#8220;Persons&#8221;:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The table above contains three records (one for each person) and five columns (P_Id, LastName, FirstName, Address, and City).</p>
<hr size="1" noshade="noshade" /><strong>SQL Statements</strong></p>
<p>Most of the actions you need to perform on a database are done with SQL statements.</p>
<p>The following SQL statement will select all the records in the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons</td>
</tr>
</tbody>
</table>
<p>In this tutorial we will teach you all about the different SQL statements.</p>
<hr size="1" noshade="noshade" /><strong>Keep in Mind That&#8230;</strong></p>
<ul type="disc">
<li>SQL is not case      sensitive</li>
</ul>
<hr size="1" noshade="noshade" /><strong>Semicolon after SQL Statements?</strong></p>
<p>Some database systems require a semicolon at the end of each SQL statement.</p>
<p>Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.</p>
<p>We are using MS Access and SQL Server 2000 and we do not have to put a semicolon after each SQL statement, but some database programs force you to use it.</p>
<hr size="1" noshade="noshade" /><strong>SQL DML and DDL</strong></p>
<p>SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).</p>
<p>The query and update commands form the DML part of SQL:</p>
<ul type="disc">
<li><strong>SELECT</strong> &#8211; extracts data      from a database</li>
<li><strong>UPDATE</strong> &#8211; updates data      in a database</li>
<li><strong>DELETE</strong> &#8211; deletes data      from a database</li>
<li><strong>INSERT INTO</strong> &#8211; inserts new      data into a database</li>
</ul>
<p>The DDL part of SQL permits database tables to be created or deleted. It also define indexes (keys), specify links between tables, and impose constraints between tables. The most important DDL statements in SQL are:</p>
<ul type="disc">
<li><strong>CREATE DATABASE</strong> &#8211; creates a new      database</li>
<li><strong>ALTER DATABASE</strong> &#8211; modifies a      database</li>
<li><strong>CREATE TABLE</strong> &#8211; creates a new      table</li>
<li><strong>ALTER TABLE</strong> &#8211; modifies a      table</li>
<li><strong>DROP TABLE</strong> &#8211; deletes a      table</li>
<li><strong>CREATE INDEX</strong> &#8211; creates an      index (search key)</li>
<li><strong>DROP INDEX</strong> &#8211; deletes an      index</li>
</ul>
<h2><span style="color:#800000;">SQL SELECT Statement</span></h2>
<hr size="1" noshade="noshade" />This chapter will explain the SELECT and the SELECT * statements.</p>
<hr size="1" noshade="noshade" />
<h2>The SQL SELECT Statement</h2>
<p>The SELECT statement is used to select data from a database.</p>
<p>The result is stored in a result table, called the result-set.</p>
<h3>SQL SELECT Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<p>and</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> SQL is not case sensitive. SELECT is the same as select.</p>
<hr size="1" noshade="noshade" />
<h2>An SQL SELECT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the columns named &#8220;LastName&#8221; and &#8220;FirstName&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SELECT * Example</h2>
<p>Now we want to select all the columns from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons</td>
</tr>
</tbody>
</table>
<p><strong>Tip:</strong> The asterisk (*) is a quick way of selecting all columns!</p>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL SELECT DISTINCT Statement</span></h2>
<hr size="1" noshade="noshade" />This chapter will explain the SELECT DISTINCT statement.</p>
<hr size="1" noshade="noshade" />
<h2>The SQL SELECT DISTINCT Statement</h2>
<p>In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.</p>
<p>The DISTINCT keyword can be used to return only distinct (different) values.</p>
<h3>SQL SELECT DISTINCT Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT DISTINCT column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SELECT DISTINCT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the distinct values from the column named &#8220;City&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT DISTINCT City FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>City</strong></td>
</tr>
<tr>
<td>Sandnes</td>
</tr>
<tr>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL WHERE Clause</span></h2>
<hr size="1" noshade="noshade" />The WHERE clause is used to filter records.</p>
<hr size="1" noshade="noshade" />
<h2>The WHERE Clause</h2>
<p>The WHERE clause is used to extract only those records that fulfill a specified criterion.</p>
<h3>SQL WHERE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name operator value</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>WHERE Clause Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the persons living in the city &#8220;Sandnes&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Quotes Around Text Fields</h2>
<p>SQL uses single quotes around text values (most database systems will also accept double quotes).</p>
<p>Although, numeric values should not be enclosed in quotes.</p>
<p>For text values:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>This is correct:SELECT * FROM Persons WHERE FirstName=&#8217;Tove&#8217;This is wrong:SELECT * FROM Persons WHERE FirstName=Tove</td>
</tr>
</tbody>
</table>
<p>For numeric values:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>This is correct:SELECT * FROM Persons WHERE Year=1965This is wrong:SELECT * FROM Persons WHERE Year=&#8217;1965&#8242;</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Operators Allowed in the WHERE Clause</h2>
<p>With the WHERE clause, the following operators can be used:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td valign="top">
<p align="center"><strong>Operator</strong></p>
</td>
<td>
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top">=</td>
<td>Equal</td>
</tr>
<tr>
<td valign="top">&lt;&gt;</td>
<td>Not   equal</td>
</tr>
<tr>
<td valign="top">&gt;</td>
<td>Greater   than</td>
</tr>
<tr>
<td valign="top">&lt;</td>
<td>Less   than</td>
</tr>
<tr>
<td valign="top">&gt;=</td>
<td>Greater   than or equal</td>
</tr>
<tr>
<td valign="top">&lt;=</td>
<td>Less   than or equal</td>
</tr>
<tr>
<td valign="top">BETWEEN</td>
<td>Between   an inclusive range</td>
</tr>
<tr>
<td valign="top">LIKE</td>
<td>Search   for a pattern</td>
</tr>
<tr>
<td valign="top">IN</td>
<td>If   you know the exact value you want to return for at least one of the columns</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> In some versions of SQL the &lt;&gt; operator may be written as !=</p>
<h2><span style="color:#800000;">SQL AND &amp; OR Operators</span></h2>
<hr size="1" noshade="noshade" />The AND &amp; OR operators are used to filter records based on more than one condition.</p>
<hr size="1" noshade="noshade" />
<h2>The AND &amp; OR Operators</h2>
<p>The AND operator displays a record if both the first condition and the second condition is true.</p>
<p>The OR operator displays a record if either the first condition or the second condition is true.</p>
<hr size="1" noshade="noshade" />
<h2>AND Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the persons with the first name equal to &#8220;Tove&#8221; AND the last name equal to &#8220;Svendson&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName=&#8217;Tove&#8217;<br />
AND LastName=&#8217;Svendson&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>OR Operator Example</h2>
<p>Now we want to select only the persons with the first name equal to &#8220;Tove&#8221; OR the first name equal to &#8220;Ola&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName=&#8217;Tove&#8217;<br />
OR FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Combining AND &amp; OR</h2>
<p>You can also combine AND and OR (use parenthesis to form complex expressions).</p>
<p>Now we want to select only the persons with the last name equal to &#8220;Svendson&#8221; AND the first name equal to &#8220;Tove&#8221; OR to &#8220;Ola&#8221;:</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons WHERE<br />
LastName=&#8217;Svendson&#8217;<br />
AND (FirstName=&#8217;Tove&#8217; OR FirstName=&#8217;Ola&#8217;)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL ORDER BY Keyword</span></h2>
<hr size="1" noshade="noshade" />The ORDER BY keyword is used to sort the result-set.</p>
<hr size="1" noshade="noshade" />
<h2>The ORDER BY Keyword</h2>
<p>The ORDER BY keyword is used to sort the result-set by a specified column.</p>
<p>The ORDER BY keyword sort the records in ascending order by default.</p>
<p>If you want to sort the records in a descending order, you can use the DESC keyword.</p>
<h3>SQL ORDER BY Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
ORDER BY column_name(s) ASC|DESC</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>ORDER BY Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn   23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select all the persons from the table above, however, we want to sort the persons by their last name.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
ORDER BY LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn   23</td>
<td>Stavanger</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>ORDER BY DESC Example</h2>
<p>Now we want to select all the persons from the table above, however, we want to sort the persons descending by their last name.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
ORDER BY LastName DESC</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn   23</td>
<td>Stavanger</td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL INSERT INTO Statement</span></h2>
<hr size="1" noshade="noshade" />The INSERT INTO statement is used to insert new records in a table.</p>
<hr size="1" noshade="noshade" />
<h2>The INSERT INTO Statement</h2>
<p>The INSERT INTO statement is used to insert a new row in a table.</p>
<h3>SQL INSERT INTO Syntax</h3>
<p>It is possible to write the INSERT INTO statement in two forms.</p>
<p>The first form doesn&#8217;t specify the column names where the data will be inserted, only their values:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO table_name<br />
VALUES (value1, value2, value3,&#8230;)</td>
</tr>
</tbody>
</table>
<p>The second form specifies both the column names and the values to be inserted:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO table_name (column1,   column2, column3,&#8230;)<br />
VALUES (value1, value2, value3,&#8230;)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL INSERT INTO Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to insert a new row in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons<br />
VALUES (4,&#8217;Nilsen&#8217;, &#8216;Johan&#8217;, &#8216;Bakken 2&#8242;, &#8216;Stavanger&#8217;)</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Insert Data Only in Specified Columns</h2>
<p>It is also possible to only add data in specific columns.</p>
<p>The following SQL statement will add a new row, but only add data in the &#8220;P_Id&#8221;, &#8220;LastName&#8221; and the &#8220;FirstName&#8221; columns:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons (P_Id, LastName,   FirstName)<br />
VALUES (5, &#8216;Tjessem&#8217;, &#8216;Jakob&#8217;)</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL UPDATE Statement</span></h2>
<hr size="1" noshade="noshade" />The UPDATE statement is used to update records in a table.</p>
<hr size="1" noshade="noshade" />
<h2>The UPDATE Statement</h2>
<p>The UPDATE statement is used to update existing records in a table.</p>
<h3>SQL UPDATE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>UPDATE table_name<br />
SET column1=value, column2=value2,&#8230;<br />
WHERE some_column=some_value</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!</p>
<hr size="1" noshade="noshade" />
<h2>SQL UPDATE Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>Now we want to update the person &#8220;Tjessem, Jakob&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>UPDATE Persons<br />
SET Address=&#8217;Nissestien 67&#8242;, City=&#8217;Sandnes&#8217;<br />
WHERE LastName=&#8217;Tjessem&#8217; AND FirstName=&#8217;Jakob&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL UPDATE Warning</h2>
<p>Be careful when updating records. If we had omitted the WHERE clause in the example above, like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>UPDATE Persons<br />
SET Address=&#8217;Nissestien 67&#8242;, City=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table would have looked like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL DELETE Statement</span></h2>
<hr size="1" noshade="noshade" />The DELETE statement is used to delete records in a table.</p>
<hr size="1" noshade="noshade" />
<h2>The DELETE Statement</h2>
<p>The DELETE statement is used to delete rows in a table.</p>
<h3>SQL DELETE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DELETE FROM table_name<br />
WHERE some_column=some_value</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!</p>
<hr size="1" noshade="noshade" />
<h2>SQL DELETE Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
<tr>
<td>5</td>
<td>Tjessem</td>
<td>Jakob</td>
<td>Nissestien   67</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Now we want to delete the person &#8220;Tjessem, Jakob&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DELETE FROM Persons<br />
WHERE LastName=&#8217;Tjessem&#8217; AND FirstName=&#8217;Jakob&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Johan</td>
<td>Bakken   2</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Delete All Rows</h2>
<p>It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DELETE FROM table_nameorDELETE * FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> Be very careful when deleting records. You cannot undo this statement!</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="8"></td>
<td>
<h1>SQL Try   It</h1>
<hr size="1" noshade="noshade" />
<h2>Test your SQL Skills</h2>
<p>On this page you can   test your SQL skills.</p>
<p>We will use the <strong>Customers</strong> table in the Northwind database:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>CompanyName</strong></td>
<td><strong>ContactName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td valign="top">Alfreds Futterkiste</td>
<td valign="top">Maria Anders</td>
<td valign="top">Obere Str. 57</td>
<td valign="top">Berlin</td>
</tr>
<tr>
<td valign="top">Berglunds snabbköp</td>
<td valign="top">Christina Berglund</td>
<td valign="top">Berguvsvägen 8</td>
<td valign="top">Luleå</td>
</tr>
<tr>
<td valign="top">Centro comercial Moctezuma</td>
<td valign="top">Francisco Chang</td>
<td valign="top">Sierras de Granada 9993</td>
<td valign="top">México D.F.</td>
</tr>
<tr>
<td valign="top">Ernst Handel</td>
<td valign="top">Roland Mendel</td>
<td valign="top">Kirchgasse 6</td>
<td valign="top">Graz</td>
</tr>
<tr>
<td valign="top">FISSA Fabrica Inter. Salchichas S.A.</td>
<td valign="top">Diego Roel</td>
<td valign="top">C/ Moralzarzal, 86</td>
<td valign="top">Madrid</td>
</tr>
<tr>
<td valign="top">Galería del gastrónomo</td>
<td valign="top">Eduardo Saavedra</td>
<td valign="top">Rambla de Cataluña, 23</td>
<td valign="top">Barcelona</td>
</tr>
<tr>
<td valign="top">Island Trading</td>
<td valign="top">Helen Bennett</td>
<td valign="top">Garden House Crowther Way</td>
<td valign="top">Cowes</td>
</tr>
<tr>
<td valign="top">Königlich Essen</td>
<td valign="top">Philip Cramer</td>
<td valign="top">Maubelstr. 90</td>
<td valign="top">Brandenburg</td>
</tr>
<tr>
<td valign="top">Laughing Bacchus Wine Cellars</td>
<td valign="top">Yoshi Tannamuri</td>
<td valign="top">1900 Oak St.</td>
<td valign="top">Vancouver</td>
</tr>
<tr>
<td valign="top">Magazzini Alimentari Riuniti</td>
<td valign="top">Giovanni Rovelli</td>
<td valign="top">Via Ludovico il Moro 22</td>
<td valign="top">Bergamo</td>
</tr>
<tr>
<td valign="top">North/South</td>
<td valign="top">Simon Crowther</td>
<td valign="top">South House 300 Queensbridge</td>
<td valign="top">London</td>
</tr>
<tr>
<td valign="top">Paris spécialités</td>
<td valign="top">Marie Bertrand</td>
<td valign="top">265, boulevard Charonne</td>
<td valign="top">Paris</td>
</tr>
<tr>
<td valign="top">Rattlesnake Canyon Grocery</td>
<td valign="top">Paula Wilson</td>
<td valign="top">2817 Milton Dr.</td>
<td valign="top">Albuquerque</td>
</tr>
<tr>
<td valign="top">Simons bistro</td>
<td valign="top">Jytte Petersen</td>
<td valign="top">Vinbæltet 34</td>
<td valign="top">København</td>
</tr>
<tr>
<td valign="top">The Big Cheese</td>
<td valign="top">Liz Nixon</td>
<td valign="top">89 Jefferson Way Suite 2</td>
<td valign="top">Portland</td>
</tr>
<tr>
<td valign="top">Vaffeljernet</td>
<td valign="top">Palle Ibsen</td>
<td valign="top">Smagsløget 45</td>
<td valign="top">Århus</td>
</tr>
<tr>
<td valign="top">Wolski Zajazd</td>
<td valign="top">Zbyszek Piestrzeniewicz</td>
<td valign="top">ul. Filtrowa 68</td>
<td valign="top">Warszawa</td>
</tr>
</tbody>
</table>
<p>To preserve space,   the table above is a subset of the Customers table used in the example below.</p>
<hr size="1" noshade="noshade" />
<h2>Try it Yourself</h2>
<p>To see how SQL works, you can copy the SQL statements below and paste them into the textarea, or you can make your own SQL statements.</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM customers</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT CompanyName, ContactName     FROM customers</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM customers WHERE     companyname LIKE &#8216;a%&#8217;</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT CompanyName, ContactName<br />
FROM customers<br />
WHERE CompanyName &gt; &#8216;a&#8217;</td>
</tr>
</tbody>
</table>
<p>When using SQL on text data,   &#8220;alfred&#8221; is greater than &#8220;a&#8221; (like in a dictionary).</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT CompanyName, ContactName<br />
FROM customers<br />
WHERE CompanyName &gt; &#8216;g&#8217;<br />
AND ContactName &gt; &#8216;g&#8217;</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL TOP Clause</span></h2>
<hr size="1" noshade="noshade" />
<h2>The TOP Clause</h2>
<p>The TOP clause is used to specify the number of records to return.</p>
<p>The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.</p>
<p><strong>Note:</strong> Not all database systems support the TOP clause.</p>
<h3>SQL Server Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT TOP number|percent   column_name(s)<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL SELECT TOP Equivalent in MySQL and Oracle</h2>
<h3>MySQL Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
LIMIT number</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT *<br />
FROM Persons<br />
LIMIT 5</td>
</tr>
</tbody>
</table>
<h3>Oracle Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE ROWNUM &lt;= number</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT *<br />
FROM Persons<br />
WHERE ROWNUM &lt;=5</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL TOP Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn   23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only the two first records in the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT TOP 2 * FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL TOP PERCENT Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
<tr>
<td>4</td>
<td>Nilsen</td>
<td>Tom</td>
<td>Vingvn   23</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select only 50% of the records in the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT TOP 50 PERCENT * FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL LIKE Operator</span></h2>
<hr size="1" noshade="noshade" />The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.</p>
<hr size="1" noshade="noshade" />
<h2>The LIKE Operator</h2>
<p>The LIKE operator is used to search for a specified pattern in a column.</p>
<h3>SQL LIKE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name LIKE pattern</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>LIKE Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons living in a city that starts with &#8220;s&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City LIKE &#8216;s%&#8217;</td>
</tr>
</tbody>
</table>
<p>The &#8220;%&#8221; sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.</p>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that ends with an &#8220;s&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City LIKE &#8216;%s&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that contains the pattern &#8220;tav&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City LIKE &#8216;%tav%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>It is also possible to select the persons living in a city that NOT contains the pattern &#8220;tav&#8221; from the &#8220;Persons&#8221; table, by using the NOT keyword.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City NOT LIKE &#8216;%tav%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Wildcards</span></h2>
<hr size="1" noshade="noshade" />SQL wildcards can be used when searching for data in a database.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Wildcards</h2>
<p>SQL wildcards can substitute for one or more characters when searching for data in a database.</p>
<p>SQL wildcards must be used with the SQL LIKE operator.</p>
<p>With SQL, the following wildcards can be used:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="15%"><strong>Wildcard</strong></td>
<td width="85%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">%</td>
<td valign="top">A   substitute for zero or more characters</td>
</tr>
<tr>
<td valign="top">_</td>
<td valign="top">A   substitute for exactly one character</td>
</tr>
<tr>
<td valign="top">[charlist]</td>
<td valign="top">Any   single character in charlist</td>
</tr>
<tr>
<td valign="top">[^charlist]or[!charlist]</td>
<td valign="top">Any   single character not in charlist</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Wildcard Examples</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Using the % Wildcard</h2>
<p>Now we want to select the persons living in a city that starts with &#8220;sa&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City LIKE &#8216;sa%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons living in a city that contains the pattern &#8220;nes&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE City LIKE &#8216;%nes%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Using the _ Wildcard</h2>
<p>Now we want to select the persons with a first name that starts with any character, followed by &#8220;la&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE FirstName LIKE &#8216;_la&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons with a last name that starts with &#8220;S&#8221;, followed by any character, followed by &#8220;end&#8221;, followed by any character, followed by &#8220;on&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;S_end_on&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Using the [charlist] Wildcard</h2>
<p>Now we want to select the persons with a last name that starts with &#8220;b&#8221; or &#8220;s&#8221; or &#8220;p&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;[bsp]%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Next, we want to select the persons with a last name that do not start with &#8220;b&#8221; or &#8220;s&#8221; or &#8220;p&#8221; from the &#8220;Persons&#8221; table.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName LIKE &#8216;[!bsp]%&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL IN Operator</span></h2>
<hr size="1" noshade="noshade" />
<h2>The IN Operator</h2>
<p>The IN operator allows you to specify multiple values in a WHERE clause.</p>
<h3>SQL IN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name IN (value1,value2,&#8230;)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>IN Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons with a last name equal to &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName IN (&#8216;Hansen&#8217;,'Pettersen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL BETWEEN Operator</span></h2>
<hr size="1" noshade="noshade" />The BETWEEN operator is used in a WHERE clause to select a range of data between two values.</p>
<hr size="1" noshade="noshade" />
<h2>The BETWEEN Operator</h2>
<p>The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.</p>
<h3>SQL BETWEEN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
BETWEEN value1 AND value2</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>BETWEEN Operator Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the persons with a last name alphabetically between &#8220;Hansen&#8221; and &#8220;Pettersen&#8221; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName<br />
BETWEEN &#8216;Hansen&#8217; AND &#8216;Pettersen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The BETWEEN operator is treated differently in different databases.</p>
<p>In some databases, persons with the LastName of &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; will not be listed, because the BETWEEN operator only selects fields that are between and excluding the test values).</p>
<p>In other databases, persons with the LastName of &#8220;Hansen&#8221; or &#8220;Pettersen&#8221; will be listed, because the BETWEEN operator selects fields that are between and including the test values).</p>
<p>And in other databases, persons with the LastName of &#8220;Hansen&#8221; will be listed, but &#8220;Pettersen&#8221; will not be listed (like the example above), because the BETWEEN operator selects fields between the test values, including the first test value and excluding the last test value.</p>
<p>Therefore: Check how your database treats the BETWEEN operator.</p>
<hr size="1" noshade="noshade" />
<h2>Example 2</h2>
<p>To display the persons outside the range in the previous example, use NOT BETWEEN:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Persons<br />
WHERE LastName<br />
NOT BETWEEN &#8216;Hansen&#8217; AND &#8216;Pettersen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Alias</span></h2>
<hr size="1" noshade="noshade" />With SQL, an alias name can be given to a table or to a column.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Alias</h2>
<p>You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names.</p>
<p>An alias name could be anything, but usually it is short.</p>
<h3>SQL Alias Syntax for Tables</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name<br />
AS alias_name</td>
</tr>
</tbody>
</table>
<h3>SQL Alias Syntax for Columns</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name AS alias_name<br />
FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Alias Example</h2>
<p>Assume we have a table called &#8220;Persons&#8221; and another table called &#8220;Product_Orders&#8221;. We will give the table aliases of &#8220;p&#8221; an &#8220;po&#8221; respectively.</p>
<p>Now we want to list all the orders that &#8220;Ola Hansen&#8221; is responsible for.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT po.OrderID, p.LastName,   p.FirstName<br />
FROM Persons AS p,<br />
Product_Orders AS po<br />
WHERE p.LastName=&#8217;Hansen&#8217;<br />
WHERE p.FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>The same SELECT statement without aliases:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Product_Orders.OrderID,   Persons.LastName, Persons.FirstName<br />
FROM Persons,<br />
Product_Orders<br />
WHERE Persons.LastName=&#8217;Hansen&#8217;<br />
WHERE Persons.FirstName=&#8217;Ola&#8217;</td>
</tr>
</tbody>
</table>
<p>As you&#8217;ll see from the two SELECT statements above; aliases can make queries easier to both write and to read.</p>
<h2><span style="color:#800000;">SQL Joins</span></h2>
<hr size="1" noshade="noshade" />SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.</p>
<hr size="1" noshade="noshade" />
<h2>SQL JOIN</h2>
<p>The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.</p>
<p>Tables in a database are often related to each other with keys.</p>
<p>A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.</p>
<p>Look at the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;P_Id&#8221; column is the primary key in the &#8220;Persons&#8221; table. This means that <strong>no</strong> two rows can have the same P_Id. The P_Id distinguishes two persons even if they have the same name.</p>
<p>Next, we have the &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;O_Id&#8221; column is the primary key in the &#8220;Orders&#8221; table and that the &#8220;P_Id&#8221; column refers to the persons in the &#8220;Persons&#8221; table without using their names.</p>
<p>Notice that the relationship between the two tables above is the &#8220;P_Id&#8221; column.</p>
<hr size="1" noshade="noshade" />
<h2>Different SQL JOINs</h2>
<p>Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.</p>
<ul type="disc">
<li><strong>JOIN</strong>: Return rows when there is at least one match in both tables</li>
<li><strong>LEFT JOIN</strong>: Return all rows from the left table, even if there are no      matches in the right table</li>
<li><strong>RIGHT JOIN</strong>: Return all rows from the right table, even if there are no      matches in the left table</li>
<li><strong>FULL JOIN</strong>: Return rows when there is a match in one of the tables</li>
</ul>
<h2><span style="color:#800000;">SQL INNER JOIN Keyword</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL INNER JOIN Keyword</h2>
<p>The INNER JOIN keyword return rows when there is at least one match in both tables.</p>
<h3>SQL INNER JOIN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
INNER JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> INNER JOIN is the same as JOIN.</p>
<hr size="1" noshade="noshade" />
<h2>SQL INNER JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons with any orders.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Persons.LastName,   Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
INNER JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
</tbody>
</table>
<p>The INNER JOIN keyword return rows when there is at least one match in both tables. If there are rows in &#8220;Persons&#8221; that do not have matches in &#8220;Orders&#8221;, those rows will NOT be listed.</p>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL LEFT JOIN Keyword</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL LEFT JOIN Keyword</h2>
<p>The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).</p>
<h3>SQL LEFT JOIN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
LEFT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> In some databases LEFT JOIN is called LEFT OUTER JOIN.</p>
<hr size="1" noshade="noshade" />
<h2>SQL LEFT JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons and their orders &#8211; if any, from the tables above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Persons.LastName,   Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
LEFT JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td></td>
</tr>
</tbody>
</table>
<p>The LEFT JOIN keyword returns all the rows from the left table (Persons), even if there are no matches in the right table (Orders).</p>
<h2><span style="color:#800000;">SQL RIGHT JOIN Keyword</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL RIGHT JOIN Keyword</h2>
<p>The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).</p>
<h3>SQL RIGHT JOIN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
RIGHT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> In some databases RIGHT JOIN is called RIGHT OUTER JOIN.</p>
<hr size="1" noshade="noshade" />
<h2>SQL RIGHT JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the orders with containing persons &#8211; if any, from the tables above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Persons.LastName,   Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
RIGHT JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td></td>
<td></td>
<td>34764</td>
</tr>
</tbody>
</table>
<p>The RIGHT JOIN keyword returns all the rows from the right table (Orders), even if there are no matches in the left table (Persons).</p>
<h2><span style="color:#800000;">SQL FULL JOIN Keyword</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL FULL JOIN Keyword</h2>
<p>The FULL JOIN keyword return rows when there is a match in one of the tables.</p>
<h3>SQL FULL JOIN Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
FROM table_name1<br />
FULL JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL FULL JOIN Example</h2>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>34764</td>
<td>15</td>
</tr>
</tbody>
</table>
<p>Now we want to list all the persons and their orders, and all the orders with their persons.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Persons.LastName,   Persons.FirstName, Orders.OrderNo<br />
FROM Persons<br />
FULL JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id<br />
ORDER BY Persons.LastName</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>OrderNo</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>22456</td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td>24562</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>77895</td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td>44678</td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td>34764</td>
</tr>
</tbody>
</table>
<p>The FULL JOIN keyword returns all the rows from the left table (Persons), and all the rows from the right table (Orders). If there are rows in &#8220;Persons&#8221; that do not have matches in &#8220;Orders&#8221;, or if there are rows in &#8220;Orders&#8221; that do not have matches in &#8220;Persons&#8221;, those rows will be listed as well.</p>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL UNION Operator</span></h2>
<hr size="1" noshade="noshade" />The SQL UNION operator combines two or more SELECT statements.</p>
<hr size="1" noshade="noshade" />
<h2>The SQL UNION Operator</h2>
<p>The UNION operator is used to combine the result-set of two or more SELECT statements.</p>
<p>Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.</p>
<h3>SQL UNION Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s) FROM table_name1<br />
UNION<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL.</p>
<h3>SQL UNION ALL Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s) FROM table_name1<br />
UNION ALL<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
</tbody>
</table>
<p><strong>PS:</strong> The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in the UNION.</p>
<hr size="1" noshade="noshade" />
<h2>SQL UNION Example</h2>
<p>Look at the following tables:</p>
<p><strong>&#8220;Employees_Norway&#8221;</strong>:</p>
<table border="1" cellspacing="0" cellpadding="0" width="60%">
<tbody>
<tr>
<td width="25%"><strong>E_ID</strong></td>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>01</td>
<td>Hansen,   Ola</td>
</tr>
<tr>
<td>02</td>
<td>Svendson,   Tove</td>
</tr>
<tr>
<td>03</td>
<td>Svendson,   Stephen</td>
</tr>
<tr>
<td>04</td>
<td>Pettersen,   Kari</td>
</tr>
</tbody>
</table>
<p><strong>&#8220;Employees_USA&#8221;</strong>:</p>
<table border="1" cellspacing="0" cellpadding="0" width="60%">
<tbody>
<tr>
<td width="25%"><strong>E_ID</strong></td>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>01</td>
<td>Turner,   Sally</td>
</tr>
<tr>
<td>02</td>
<td>Kent,   Clark</td>
</tr>
<tr>
<td>03</td>
<td>Svendson,   Stephen</td>
</tr>
<tr>
<td>04</td>
<td>Scott,   Stephen</td>
</tr>
</tbody>
</table>
<p>Now we want to list <strong>all the different</strong> employees in Norway and USA.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT E_Name FROM Employees_Norway<br />
UNION<br />
SELECT E_Name FROM Employees_USA</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="60%">
<tbody>
<tr>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>Hansen,   Ola</td>
</tr>
<tr>
<td>Svendson,   Tove</td>
</tr>
<tr>
<td>Svendson,   Stephen</td>
</tr>
<tr>
<td>Pettersen,   Kari</td>
</tr>
<tr>
<td>Turner,   Sally</td>
</tr>
<tr>
<td>Kent,   Clark</td>
</tr>
<tr>
<td>Scott,   Stephen</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> This command cannot be used to list all employees in Norway and USA. In the example above we have two employees with equal names, and only one of them will be listed. The UNION command selects only distinct values.</p>
<hr size="1" noshade="noshade" />
<h2>SQL UNION ALL Example</h2>
<p>Now we want to list <strong>all</strong> employees in Norway and USA:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT E_Name FROM Employees_Norway<br />
UNION ALL<br />
SELECT E_Name FROM Employees_USA</td>
</tr>
</tbody>
</table>
<p><strong>Result</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="60%">
<tbody>
<tr>
<td width="35%"><strong>E_Name</strong></td>
</tr>
<tr>
<td>Hansen,   Ola</td>
</tr>
<tr>
<td>Svendson,   Tove</td>
</tr>
<tr>
<td>Svendson,   Stephen</td>
</tr>
<tr>
<td>Pettersen,   Kari</td>
</tr>
<tr>
<td>Turner,   Sally</td>
</tr>
<tr>
<td>Kent,   Clark</td>
</tr>
<tr>
<td>Svendson,   Stephen</td>
</tr>
<tr>
<td>Scott,   Stephen</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL SELECT INTO Statement</span></h2>
<hr size="1" noshade="noshade" />The SQL SELECT INTO statement can be used to create backup copies of tables.</p>
<hr size="1" noshade="noshade" />
<h2>The SQL SELECT INTO Statement</h2>
<p>The SELECT INTO statement selects data from one table and inserts it into a different table.</p>
<p>The SELECT INTO statement is most often used to create backup copies of tables.</p>
<h3>SQL SELECT INTO Syntax</h3>
<p>We can select all columns into the new table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT *<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_tablename</td>
</tr>
</tbody>
</table>
<p>Or we can select only the columns we want into the new table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name(s)<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_tablename</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL SELECT INTO Example</h2>
<p><strong>Make a Backup Copy</strong> &#8211; Now we want to make an exact copy of the data in our &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT *<br />
INTO Persons_Backup<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<p>We can also use the IN clause to copy the table into another database:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT *<br />
INTO Persons_Backup IN &#8216;Backup.mdb&#8217;<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<p>We can also copy only a few fields into the new table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LastName,FirstName<br />
INTO Persons_Backup<br />
FROM Persons</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL SELECT INTO &#8211; With a WHERE Clause</h2>
<p>We can also add a WHERE clause.</p>
<p>The following SQL statement creates a &#8220;Persons_Backup&#8221; table with only the persons who lives in the city &#8220;Sandnes&#8221;:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LastName,Firstname<br />
INTO Persons_Backup<br />
FROM Persons<br />
WHERE City=&#8217;Sandnes&#8217;</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL SELECT INTO &#8211; Joined Tables</h2>
<p>Selecting data from more than one table is also possible.</p>
<p>The following example creates a &#8220;Persons_Order_Backup&#8221; table contains data from the two tables &#8220;Persons&#8221; and &#8220;Orders&#8221;:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Persons.LastName,Orders.OrderNo<br />
INTO Persons_Order_Backup<br />
FROM Persons<br />
INNER JOIN Orders<br />
ON Persons.P_Id=Orders.P_Id</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL CREATE DATABASE Statement</span></h2>
<hr size="1" noshade="noshade" />
<h2>The CREATE DATABASE Statement</h2>
<p>The CREATE DATABASE statement is used to create a database.</p>
<h3>SQL CREATE DATABASE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE DATABASE database_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>CREATE DATABASE Example</h2>
<p>Now we want to create a database called &#8220;my_db&#8221;.</p>
<p>We use the following CREATE DATABASE statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE DATABASE my_db</td>
</tr>
</tbody>
</table>
<p>Database tables can be added with the CREATE TABLE statement.</p>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL CREATE TABLE Statement</span></h2>
<hr size="1" noshade="noshade" />
<h2>The CREATE TABLE Statement</h2>
<p>The CREATE TABLE statement is used to create a table in a database.</p>
<h3>SQL CREATE TABLE Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE table_name<br />
(<br />
column_name1 data_type,<br />
column_name2 data_type,<br />
column_name3 data_type,<br />
&#8230;.<br />
)</td>
</tr>
</tbody>
</table>
<p>The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete <a href="http://www.w3schools.com/SQL/sql_datatypes.asp">Data Types reference</a>.</p>
<hr size="1" noshade="noshade" />
<h2>CREATE TABLE Example</h2>
<p>Now we want to create a table called &#8220;Persons&#8221; that contains five columns: P_Id, LastName, FirstName, Address, and City.</p>
<p>We use the following CREATE TABLE statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int,<br />
LastName varchar(255),<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The P_Id column is of type int and will hold a number. The LastName, FirstName, Address, and City columns are of type varchar with a maximum length of 255 characters.</p>
<p>The empty &#8220;Persons&#8221; table will now look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>The empty table can be filled with data with the INSERT INTO statement.</p>
<h2><span style="color:#800000;">SQL Constraints</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL Constraints</h2>
<p>Constraints are used to limit the type of data that can go into a table.</p>
<p>Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).</p>
<p>We will focus on the following constraints:</p>
<ul type="disc">
<li>NOT NULL</li>
<li>UNIQUE</li>
<li>PRIMARY KEY</li>
<li>FOREIGN KEY</li>
<li>CHECK</li>
<li>DEFAULT</li>
</ul>
<p>The next chapters will describe each constraint in details.</p>
<h2><span style="color:#800000;">SQL NOT NULL Constraint</span></h2>
<hr size="1" noshade="noshade" />By default, a table column can hold NULL values.</p>
<hr size="1" noshade="noshade" />
<h2>SQL NOT NULL Constraint</h2>
<p>The NOT NULL constraint enforces a column to NOT accept NULL values.</p>
<p>The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.</p>
<p>The following SQL enforces the &#8220;P_Id&#8221; column and the &#8220;LastName&#8221; column to not accept NULL values:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL UNIQUE Constraint</span></h2>
<hr size="2" />
<h2>SQL UNIQUE Constraint</h2>
<p>The UNIQUE constraint uniquely identifies each record in a database table.</p>
<p>The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.</p>
<p>A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.</p>
<p>Note that you can have have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.</p>
<hr size="2" />
<h2>SQL UNIQUE Constraint on CREATE TABLE</h2>
<p>The following SQL creates a UNIQUE constraint on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
UNIQUE (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL UNIQUE,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a UNIQUE constraint on multiple columns, use the following SQL syntax:constraint, and for defining a UNIQUE</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)<br />
)</td>
</tr>
</tbody>
</table>
<hr size="2" />
<h2>SQL UNIQUE Constraint on ALTER TABLE</h2>
<p>To create a UNIQUE constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD UNIQUE (P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a UNIQUE constraint, and for defining a UNIQUE constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)</td>
</tr>
</tbody>
</table>
<hr size="2" />
<h2>To DROP a UNIQUE Constraint</h2>
<p>To drop a UNIQUE constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP INDEX uc_PersonID</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT uc_PersonID</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL PRIMARY KEY Constraint</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL PRIMARY KEY Constraint</h2>
<p>The PRIMARY KEY constraint uniquely identifies each record in a database table.</p>
<p>Primary keys must contain unique values.</p>
<p>A primary key column cannot contain NULL values.</p>
<p>Each table should have a primary key, and each table can have only one primary key.</p>
<hr size="1" noshade="noshade" />
<h2>SQL PRIMARY KEY Constraint on CREATE TABLE</h2>
<p>The following SQL creates a PRIMARY KEY on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
PRIMARY KEY (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL PRIMARY KEY,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)<br />
)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL PRIMARY KEY Constraint on ALTER TABLE</h2>
<p>To create a PRIMARY KEY constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD PRIMARY KEY (P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> If you use the ALTER TABLE statement to add a primary key, the primary key column(s) must already have been declared to not contain NULL values (when the table was first created).</p>
<hr size="1" noshade="noshade" />
<h2>To DROP a PRIMARY KEY Constraint</h2>
<p>To drop a PRIMARY KEY constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP PRIMARY KEY</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT pk_PersonID</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL FOREIGN KEY Constraint</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL FOREIGN KEY Constraint</h2>
<p>A FOREIGN KEY in one table points to a PRIMARY KEY in another table.</p>
<p>Let&#8217;s illustrate the foreign key with an example. Look at the following two tables:</p>
<p>The &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td width="15%"><strong>O_Id</strong></td>
<td width="20%"><strong>OrderNo</strong></td>
<td width="15%"><strong>P_Id</strong></td>
</tr>
<tr>
<td>1</td>
<td>77895</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>44678</td>
<td>3</td>
</tr>
<tr>
<td>3</td>
<td>22456</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>24562</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>Note that the &#8220;P_Id&#8221; column in the &#8220;Orders&#8221; table points to the &#8220;P_Id&#8221; column in the &#8220;Persons&#8221; table.</p>
<p>The &#8220;P_Id&#8221; column in the &#8220;Persons&#8221; table is the PRIMARY KEY in the &#8220;Persons&#8221; table.</p>
<p>The &#8220;P_Id&#8221; column in the &#8220;Orders&#8221; table is a FOREIGN KEY in the &#8220;Orders&#8221; table.</p>
<p>The FOREIGN KEY constraint is used to prevent actions that would destroy link between tables.</p>
<p>The FOREIGN KEY constraint also prevents that invalid data is inserted into the foreign key column, because it has to be one of the values contained in the table it points to.</p>
<hr size="1" noshade="noshade" />
<h2>SQL FOREIGN KEY Constraint on CREATE TABLE</h2>
<p>The following SQL creates a FOREIGN KEY on the &#8220;P_Id&#8221; column when the &#8220;Orders&#8221; table is created:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
PRIMARY KEY (O_Id),<br />
FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL PRIMARY KEY,<br />
OrderNo int NOT NULL,<br />
P_Id int FOREIGN KEY REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
PRIMARY KEY (O_Id),<br />
CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL FOREIGN KEY Constraint on ALTER TABLE</h2>
<p>To create a FOREIGN KEY constraint on the &#8220;P_Id&#8221; column when the &#8220;Orders&#8221; table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
ADD FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
ADD CONSTRAINT fk_PerOrders<br />
FOREIGN KEY (P_Id)<br />
REFERENCES Persons(P_Id)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>To DROP a FOREIGN KEY Constraint</h2>
<p>To drop a FOREIGN KEY constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
DROP FOREIGN KEY fk_PerOrders</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Orders<br />
DROP CONSTRAINT fk_PerOrders</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL CHECK Constraint</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL CHECK Constraint</h2>
<p>The CHECK constraint is used to limit the value range that can be placed in a column.</p>
<p>If you define a CHECK constraint on a single column it allows only certain values for this column.</p>
<p>If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.</p>
<hr size="1" noshade="noshade" />
<h2>SQL CHECK Constraint on CREATE TABLE</h2>
<p>The following SQL creates a CHECK constraint on the &#8220;P_Id&#8221; column when the &#8220;Persons&#8221; table is created. The CHECK constraint specifies that the column &#8220;P_Id&#8221; must only include integers greater than 0.</p>
<p><strong>My SQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CHECK (P_Id&gt;0)<br />
)</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL CHECK (P_Id&gt;0),<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
CONSTRAINT chk_Person CHECK (P_Id&gt;0 AND City=&#8217;Sandnes&#8217;)<br />
)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL CHECK Constraint on ALTER TABLE</h2>
<p>To create a CHECK constraint on the &#8220;P_Id&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CHECK (P_Id&gt;0)</td>
</tr>
</tbody>
</table>
<p>To allow naming of a CHECK constraint, and for defining a CHECK constraint on multiple columns, use the following SQL syntax:</p>
<p><strong>MySQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD CONSTRAINT chk_Person CHECK (P_Id&gt;0 AND City=&#8217;Sandnes&#8217;)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>To DROP a CHECK Constraint</h2>
<p>To drop a CHECK constraint, use the following SQL:</p>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP CONSTRAINT chk_Person</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL DEFAULT Constraint</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>SQL DEFAULT Constraint</h2>
<p>The DEFAULT constraint is used to insert a default value into a column.</p>
<p>The default value will be added to all new records, if no other value is specified.</p>
<hr size="1" noshade="noshade" />
<h2>SQL DEFAULT Constraint on CREATE TABLE</h2>
<p>The following SQL creates a DEFAULT constraint on the &#8220;City&#8221; column when the &#8220;Persons&#8221; table is created:</p>
<p><strong>My SQL / SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255) DEFAULT &#8216;Sandnes&#8217;<br />
)</td>
</tr>
</tbody>
</table>
<p>The DEFAULT constraint can also be used to insert system values, by using functions like GETDATE():</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
O_Id int NOT NULL,<br />
OrderNo int NOT NULL,<br />
P_Id int,<br />
OrderDate date DEFAULT GETDATE()<br />
)</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL DEFAULT Constraint on ALTER TABLE</h2>
<p>To create a DEFAULT constraint on the &#8220;City&#8221; column when the table is already created, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER City SET DEFAULT &#8216;SANDNES&#8217;</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER COLUMN City SET DEFAULT &#8216;SANDNES&#8217;</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>To DROP a DEFAULT Constraint</h2>
<p>To drop a DEFAULT constraint, use the following SQL:</p>
<p><strong>MySQL:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER City DROP DEFAULT</td>
</tr>
</tbody>
</table>
<p><strong>SQL Server / Oracle / MS Access:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER COLUMN City DROP DEFAULT</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL CREATE INDEX Statement</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<p>The CREATE INDEX statement is used to create indexes in tables.</p>
<p>Indexes allow the database application to find data fast; without reading the whole table.</p>
<hr size="1" noshade="noshade" />
<h2>Indexes</h2>
<p>An index can be created in a table to find data more quickly and efficiently.</p>
<p>The users cannot see the indexes, they are just used to speed up searches/queries.</p>
<p><strong>Note:</strong> Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.</p>
<h3>SQL CREATE INDEX Syntax</h3>
<p>Creates an index on a table. Duplicate values are allowed:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE INDEX index_name<br />
ON table_name (column_name)</td>
</tr>
</tbody>
</table>
<h3>SQL CREATE UNIQUE INDEX Syntax</h3>
<p>Creates a unique index on a table. Duplicate values are not allowed:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE UNIQUE INDEX index_name<br />
ON table_name (column_name)</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The syntax for creating indexes varies amongst different databases. Therefore: Check the syntax for creating indexes in your database.</p>
<hr size="1" noshade="noshade" />
<h2>CREATE INDEX Example</h2>
<p>The SQL statement below creates an index named &#8220;PIndex&#8221; on the &#8220;LastName&#8221; column in the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE INDEX PIndex<br />
ON Persons (LastName)</td>
</tr>
</tbody>
</table>
<p>If you want to create an index on a combination of columns, you can list the column names within the parentheses, separated by commas:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE INDEX PIndex<br />
ON Persons (LastName, FirstName)</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL DROP INDEX, DROP TABLE, and DROP DATABASE</span></h2>
<hr size="1" noshade="noshade" />Indexes, tables, and databases can easily be deleted/removed with the DROP statement.</p>
<hr size="1" noshade="noshade" />
<h2>The DROP INDEX Statement</h2>
<p>The DROP INDEX statement is used to delete an index in a table.</p>
<h3>DROP INDEX Syntax for MS Access:</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP INDEX index_name ON table_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for MS SQL Server:</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP INDEX table_name.index_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for DB2/Oracle:</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP INDEX index_name</td>
</tr>
</tbody>
</table>
<h3>DROP INDEX Syntax for MySQL:</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE table_name DROP INDEX   index_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>The DROP TABLE Statement</h2>
<p>The DROP TABLE statement is used to delete a table.</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP TABLE table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>The DROP DATABASE Statement</h2>
<p>The DROP DATABASE statement is used to delete a database.</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP DATABASE database_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>The TRUNCATE TABLE Statement</h2>
<p>What if we only want to delete the data inside the table, and not the table itself?</p>
<p>Then, use the TRUNCATE TABLE statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>TRUNCATE TABLE table_name</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL ALTER TABLE Statement</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The ALTER TABLE Statement</h2>
<p>The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.</p>
<h3>SQL ALTER TABLE Syntax</h3>
<p>To add a column in a table, use the following syntax:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
ADD column_name datatype</td>
</tr>
</tbody>
</table>
<p>To delete a column in a table, use the following syntax (notice that some database systems don&#8217;t allow deleting a column):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
DROP COLUMN column_name</td>
</tr>
</tbody>
</table>
<p>To change the data type of a column in a table, use the following syntax:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE table_name<br />
ALTER COLUMN column_name datatype</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL ALTER TABLE Example</h2>
<p>Look at the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to add a column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ADD DateOfBirth date</td>
</tr>
</tbody>
</table>
<p>Notice that the new column, &#8220;DateOfBirth&#8221;, is of type date and is going to hold a date. The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MS Access, MySQL, and SQL Server, go to our complete <a href="http://www.w3schools.com/sql/sql_datatypes.asp">Data Types reference</a>.</p>
<p>The &#8220;Persons&#8221; table will now like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
<td><strong>DateOfBirth</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
<td></td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>Change Data Type Example</h2>
<p>Now we want to change the data type of the column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
ALTER COLUMN DateOfBirth year</td>
</tr>
</tbody>
</table>
<p>Notice that the &#8220;DateOfBirth&#8221; column is now of type year and is going to hold a year in a two-digit or four-digit format.</p>
<hr size="1" noshade="noshade" />
<h2>DROP COLUMN Example</h2>
<p>Next, we want to delete the column named &#8220;DateOfBirth&#8221; in the &#8220;Persons&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons<br />
DROP COLUMN DateOfBirth</td>
</tr>
</tbody>
</table>
<p>The &#8220;Persons&#8221; table will now like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL AUTO INCREMENT Field</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<p>Auto-increment allows a unique number to be generated when a new record is inserted into a table.</p>
<hr size="1" noshade="noshade" />
<h2>AUTO INCREMENT a Field</h2>
<p>Very often we would like the value of the primary key field to be created automatically every time a new record is inserted.</p>
<p>We would like to create an auto-increment field in a table.</p>
<hr size="1" noshade="noshade" />
<h2>Syntax for MySQL</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int NOT NULL AUTO_INCREMENT,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255),<br />
PRIMARY KEY (P_Id)<br />
)</td>
</tr>
</tbody>
</table>
<p>MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.</p>
<p>To let the AUTO_INCREMENT sequence start with another value, use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>ALTER TABLE Persons AUTO_INCREMENT=100</td>
</tr>
</tbody>
</table>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons   (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<hr size="1" noshade="noshade" />
<h2>Syntax for SQL Server</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id int PRIMARY KEY IDENTITY,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for IDENTITY is 1, and it will increment by 1 for each new record.</p>
<p>To specify that the &#8220;P_Id&#8221; column should start at value 10 and increment by 5, change the identity to IDENTITY(10,5).</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons   (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<hr size="1" noshade="noshade" />
<h2>Syntax for Access</h2>
<p>The following SQL statement defines the &#8220;P_Id&#8221; column to be an auto-increment primary key field in the &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Persons<br />
(<br />
P_Id PRIMARY KEY AUTOINCREMENT,<br />
LastName varchar(255) NOT NULL,<br />
FirstName varchar(255),<br />
Address varchar(255),<br />
City varchar(255)<br />
)</td>
</tr>
</tbody>
</table>
<p>The MS Access uses the AUTOINCREMENT keyword to perform an auto-increment feature.</p>
<p>By default, the starting value for AUTOINCREMENT is 1, and it will increment by 1 for each new record.</p>
<p>To specify that the &#8220;P_Id&#8221; column should start at value 10 and increment by 5, change the autoincrement to AUTOINCREMENT(10,5).</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will not have to specify a value for the &#8220;P_Id&#8221; column (a unique value will be added automatically):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons   (FirstName,LastName)<br />
VALUES (&#8216;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned a unique value. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<hr size="1" noshade="noshade" />
<h2>Syntax for Oracle</h2>
<p>In Oracle the code is a little bit more tricky.</p>
<p>You will have to create an auto-increment field with the sequence object (this object generates a number sequence).</p>
<p>Use the following CREATE SEQUENCE syntax:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE SEQUENCE seq_person<br />
MINVALUE 1<br />
START WITH 1<br />
INCREMENT BY 1<br />
CACHE 10</td>
</tr>
</tbody>
</table>
<p>The code above creates a sequence object called seq_person, that starts with 1 and will increment by 1. It will also cache up to 10 values for performance. The cache option specifies how many sequence values will be stored in memory for faster access.</p>
<p>To insert a new record into the &#8220;Persons&#8221; table, we will have to use the nextval function (this function retrieves the next value from seq_person sequence):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Persons   (P_Id,FirstName,LastName)<br />
VALUES (seq_person.nextval,&#8217;Lars&#8217;,'Monsen&#8217;)</td>
</tr>
</tbody>
</table>
<p>The SQL statement above would insert a new record into the &#8220;Persons&#8221; table. The &#8220;P_Id&#8221; column would be assigned the next number from the seq_person sequence. The &#8220;FirstName&#8221; column would be set to &#8220;Lars&#8221; and the &#8220;LastName&#8221; column would be set to &#8220;Monsen&#8221;.</p>
<h2><span style="color:#800000;">SQL Views</span></h2>
<hr size="1" noshade="noshade" />A view is a virtual table.</p>
<p>This chapter shows how to create, update, and delete a view.</p>
<hr size="1" noshade="noshade" />
<h2>SQL CREATE VIEW Statement</h2>
<p>In SQL, a view is a virtual table based on the result-set of an SQL statement.</p>
<p>A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.</p>
<p>You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.</p>
<h3>SQL CREATE VIEW Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> A view always shows up-to-date data! The database engine recreates the data, using the view&#8217;s SQL statement, every time a user queries a view.</p>
<hr size="1" noshade="noshade" />
<h2>SQL CREATE VIEW Examples</h2>
<p>If you have the Northwind database you can see that it has several views installed by default.</p>
<p>The view &#8220;Current Product List&#8221; lists all active products (products that are not discontinued) from the &#8220;Products&#8221; table. The view is created with the following SQL:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE VIEW [Current Product List] AS<br />
SELECT ProductID,ProductName<br />
FROM Products<br />
WHERE Discontinued=No</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM [Current Product List]</td>
</tr>
</tbody>
</table>
<p>Another view in the Northwind sample database selects every product in the &#8220;Products&#8221; table with a unit price higher than the average unit price:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE VIEW [Products Above Average   Price] AS<br />
SELECT ProductName,UnitPrice<br />
FROM Products<br />
WHERE UnitPrice&gt;(SELECT AVG(UnitPrice) FROM Products)</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM [Products Above Average   Price]</td>
</tr>
</tbody>
</table>
<p>Another view in the Northwind database calculates the total sale for each category in 1997. Note that this view selects its data from another view called &#8220;Product Sales for 1997&#8243;:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE VIEW [Category Sales For 1997]   AS<br />
SELECT DISTINCT CategoryName,Sum(ProductSales) AS CategorySales<br />
FROM [Product Sales for 1997]<br />
GROUP BY CategoryName</td>
</tr>
</tbody>
</table>
<p>We can query the view above as follows:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM [Category Sales For   1997]</td>
</tr>
</tbody>
</table>
<p>We can also add a condition to the query. Now we want to see the total sale only for the category &#8220;Beverages&#8221;:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM [Category Sales For   1997]<br />
WHERE CategoryName=&#8217;Beverages&#8217;</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Updating a View</h2>
<p>You can update a view by using the following syntax:</p>
<h3>SQL CREATE OR REPLACE VIEW Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE OR REPLACE VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
</tbody>
</table>
<p>Now we want to add the &#8220;Category&#8221; column to the &#8220;Current Product List&#8221; view. We will update the view with the following SQL:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE VIEW [Current Product List] AS<br />
SELECT ProductID,ProductName,Category<br />
FROM Products<br />
WHERE Discontinued=No</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Dropping a View</h2>
<p>You can delete a view with the DROP VIEW command.</p>
<h3>SQL DROP VIEW Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DROP VIEW view_name</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Date Functions</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>SQL Dates</h2>
<p>The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database.</p>
<p>As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated.</p>
<p>Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.</p>
<hr size="1" noshade="noshade" />
<h2>MySQL Date Functions</h2>
<p>The following table lists the most important built-in date functions in MySQL:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_now.asp">NOW()</a></td>
<td>Returns   the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_curdate.asp">CURDATE()</a></td>
<td>Returns   the current date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_curtime.asp">CURTIME()</a></td>
<td>Returns   the current time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date.asp">DATE()</a></td>
<td>Extracts   the date part of a date or date/time expression</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_extract.asp">EXTRACT()</a></td>
<td>Returns   a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_add.asp">DATE_ADD()</a></td>
<td>Adds   a specified time interval to a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_sub.asp">DATE_SUB()</a></td>
<td>Subtracts   a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datediff_mysql.asp">DATEDIFF()</a></td>
<td>Returns   the number of days between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_format.asp">DATE_FORMAT()</a></td>
<td>Displays   date/time data in different formats</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Server Date Functions</h2>
<p>The following table lists the most important built-in date functions in SQL Server:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_getdate.asp">GETDATE()</a></td>
<td>Returns   the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datepart.asp">DATEPART()</a></td>
<td>Returns   a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_dateadd.asp">DATEADD()</a></td>
<td>Adds   or subtracts a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datediff.asp">DATEDIFF()</a></td>
<td>Returns   the time between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_convert.asp">CONVERT()</a></td>
<td>Displays   date/time data in different formats</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Date Data Types</h2>
<p><strong>MySQL</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul type="disc">
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>YEAR &#8211; format YYYY or YY</li>
</ul>
<p><strong>SQL Server</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul type="disc">
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>SMALLDATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: a unique number</li>
</ul>
<p><strong>Note:</strong> The date types are chosen for a column when you create a new table in your database!</p>
<p>For an overview of all data types available, go to our complete <a href="http://www.w3schools.com/sql/sql_datatypes.asp">Data Types reference</a>.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Working with Dates</h2>
<p>You can compare two dates easily if there is no time component involved!</p>
<p>Assume we have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>2</td>
<td>Camembert   Pierrot</td>
<td>2008-11-09</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone   Fabioli</td>
<td>2008-10-29</td>
</tr>
</tbody>
</table>
<p>Now we want to select the records with an OrderDate of &#8220;2008-11-11&#8243; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE   OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11</td>
</tr>
</tbody>
</table>
<p>Now, assume that the &#8220;Orders&#8221; table looks like this (notice the time component in the &#8220;OrderDate&#8221; column):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11   13:23:44</td>
</tr>
<tr>
<td>2</td>
<td>Camembert   Pierrot</td>
<td>2008-11-09   15:45:21</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11   11:12:01</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone   Fabioli</td>
<td>2008-10-29   14:56:59</td>
</tr>
</tbody>
</table>
<p>If we use the same SELECT statement as above:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE   OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>we will get no result! This is because the query is looking only for dates with no time portion.</p>
<p><strong>Tip:</strong> If you want to keep your queries simple and easy to maintain, do not allow time components in your dates!</p>
<h2><span style="color:#800000;">SQL NULL Values</span></h2>
<hr size="1" noshade="noshade" />NULL values represent missing unknown data.</p>
<p>By default, a table column can hold NULL values.</p>
<p>This chapter will explain the IS NULL and IS NOT NULL operators.</p>
<hr size="1" noshade="noshade" />
<h2>SQL NULL Values</h2>
<p>If a column in a table is optional, we can insert a new record or update an existing record without adding a value to this column. This means that the field will be saved with a NULL value.</p>
<p>NULL values are treated differently from other values.</p>
<p>NULL is used as a placeholder for unknown or inapplicable values.</p>
<p><strong>Note:</strong> It is not possible to compare NULL and 0; they are not equivalent.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Working with NULL Values</h2>
<p>Look at the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td></td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td></td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Suppose that the &#8220;Address&#8221; column in the &#8220;Persons&#8221; table is optional. This means that if we insert a record with no value for the &#8220;Address&#8221; column, the &#8220;Address&#8221; column will be saved with a NULL value.</p>
<p>How can we test for NULL values?</p>
<p>It is not possible to test for NULL values with comparison operators, such as =, &lt;, or &lt;&gt;.</p>
<p>We will have to use the IS NULL and IS NOT NULL operators instead.</p>
<hr size="1" noshade="noshade" />
<h2>SQL IS NULL</h2>
<p>How do we select only the records with NULL values in the &#8220;Address&#8221; column?</p>
<p>We will have to use the IS NULL operator:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LastName,FirstName,Address FROM   Persons<br />
WHERE Address IS NULL</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>Ola</td>
<td></td>
</tr>
<tr>
<td>Pettersen</td>
<td>Kari</td>
<td></td>
</tr>
</tbody>
</table>
<p><strong>Tip:</strong> Always use IS NULL to look for NULL values.</p>
<hr size="1" noshade="noshade" />
<h2>SQL IS NOT NULL</h2>
<p>How do we select only the records with no NULL values in the &#8220;Address&#8221; column?</p>
<p>We will have to use the IS NOT NULL operator:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LastName,FirstName,Address FROM   Persons<br />
WHERE Address IS NOT NULL</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
</tr>
<tr>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
</tr>
</tbody>
</table>
<p>In the next chapter we will look at the ISNULL(), NVL(), IFNULL() and COALESCE() functions.</p>
<h2><span style="color:#800000;">SQL NULL Functions</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>SQL ISNULL(), NVL(), IFNULL() and COALESCE() Functions</h2>
<p>Look at the following &#8220;Products&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>UnitsInStock</strong></td>
<td><strong>UnitsOnOrder</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>10.45</td>
<td>16</td>
<td>15</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>32.56</td>
<td>23</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>15.67</td>
<td>9</td>
<td>20</td>
</tr>
</tbody>
</table>
<p>Suppose that the &#8220;UnitsOnOrder&#8221; column is optional, and may contain NULL values.</p>
<p>We have the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT ProductName,UnitPrice*(UnitsInStock+UnitsOnOrder)<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>In the example above, if any of the &#8220;UnitsOnOrder&#8221; values are NULL, the result is NULL.</p>
<p>Microsoft&#8217;s ISNULL() function is used to specify how we want to treat NULL values.</p>
<p>The NVL(), IFNULL(), and COALESCE() functions can also be used to achieve the same result.</p>
<p>In this case we want NULL values to be zero.</p>
<p>Below, if &#8220;UnitsOnOrder&#8221; is NULL it will not harm the calculation, because ISNULL() returns a zero if the value is NULL:</p>
<p><strong>SQL Server / MS Access</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   ProductName,UnitPrice*(UnitsInStock+ISNULL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p><strong>Oracle</strong></p>
<p>Oracle does not have an ISNULL() function. However, we can use the NVL() function to achieve the same result:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   ProductName,UnitPrice*(UnitsInStock+NVL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p><strong>MySQL</strong></p>
<p>MySQL does have an ISNULL() function. However, it works a little bit different from Microsoft&#8217;s ISNULL() function.</p>
<p>In MySQL we can use the IFNULL() function, like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>or we can use the COALESCE() function, like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   ProductName,UnitPrice*(UnitsInStock+COALESCE(UnitsOnOrder,0))<br />
FROM Products</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Data Types</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<p>Data types and ranges for Microsoft Access, MySQL and SQL Server.</p>
<hr size="1" noshade="noshade" />
<h2>Microsoft Access Data Types</h2>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">Text</td>
<td valign="top">Use   for text or combinations of text and numbers. 255 characters maximum</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">Memo</td>
<td valign="top">Memo   is used for larger amounts of text. Stores up to 65,536 characters. <strong>Note:</strong> You cannot sort a memo field. However, they are searchable</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">Byte</td>
<td valign="top">Allows   whole numbers from 0 to 255</td>
<td valign="top">1   byte</td>
</tr>
<tr>
<td valign="top">Integer</td>
<td valign="top">Allows   whole numbers between -32,768 and 32,767</td>
<td valign="top">2   bytes</td>
</tr>
<tr>
<td valign="top">Long</td>
<td valign="top">Allows   whole numbers between -2,147,483,648 and 2,147,483,647</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">Single</td>
<td valign="top">Single   precision floating-point. Will handle most decimals</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">Double</td>
<td valign="top">Double   precision floating-point. Will handle most decimals</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">Currency</td>
<td valign="top">Use   for currency. Holds up to 15 digits of whole dollars, plus 4 decimal places. <strong>Tip:</strong> You can choose which country&#8217;s currency to use</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">AutoNumber</td>
<td valign="top">AutoNumber   fields automatically give each record its own number, usually starting at 1</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">Date/Time</td>
<td valign="top">Use   for dates and times</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">Yes/No</td>
<td valign="top">A logical field can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False (equivalent to -1 and 0). <strong>Note:</strong> Null   values are not allowed in Yes/No fields</td>
<td valign="top">1   bit</td>
</tr>
<tr>
<td valign="top">Ole   Object</td>
<td valign="top">Can   store pictures, audio, video, or other BLOBs (Binary Large OBjects)</td>
<td valign="top">up   to 1GB</td>
</tr>
<tr>
<td valign="top">Hyperlink</td>
<td valign="top">Contain   links to other files, including web pages</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">Lookup   Wizard</td>
<td valign="top">Let   you type a list of options, which can then be chosen from a drop-down list</td>
<td valign="top">4   bytes</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>MySQL Data Types</h2>
<p>In MySQL there are three main types : text, number, and Date/Time types.</p>
<p><strong>Text types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">CHAR(size)</td>
<td valign="top">Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters</td>
</tr>
<tr>
<td valign="top">VARCHAR(size)</td>
<td valign="top">Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. <strong>Note:</strong> If you put a greater value than 255 it will be   converted to a TEXT type</td>
</tr>
<tr>
<td valign="top">TINYTEXT</td>
<td valign="top">Holds   a string with a maximum length of 255 characters</td>
</tr>
<tr>
<td valign="top">TEXT</td>
<td valign="top">Holds   a string with a maximum length of 65,535 characters</td>
</tr>
<tr>
<td valign="top">BLOB</td>
<td valign="top">For   BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data</td>
</tr>
<tr>
<td valign="top">MEDIUMTEXT</td>
<td valign="top">Holds   a string with a maximum length of 16,777,215 characters</td>
</tr>
<tr>
<td valign="top">MEDIUMBLOB</td>
<td valign="top">For   BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data</td>
</tr>
<tr>
<td valign="top">LONGTEXT</td>
<td valign="top">Holds   a string with a maximum length of 4,294,967,295 characters</td>
</tr>
<tr>
<td valign="top">LONGBLOB</td>
<td valign="top">For   BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data</td>
</tr>
<tr>
<td valign="top">ENUM(x,y,z,etc.)</td>
<td valign="top">Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.<strong>Note:</strong> The values are sorted in the   order you enter them.You enter the possible   values in this format: ENUM(&#8216;X&#8217;,'Y&#8217;,'Z&#8217;)</td>
</tr>
<tr>
<td valign="top">SET</td>
<td valign="top">Similar   to ENUM except that SET may contain up to 64 list items and can store more   than one choice</td>
</tr>
</tbody>
</table>
<p><strong>Number types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">TINYINT(size)</td>
<td valign="top">-128   to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be   specified in parenthesis</td>
</tr>
<tr>
<td valign="top">SMALLINT(size)</td>
<td valign="top">-32768   to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be   specified in parenthesis</td>
</tr>
<tr>
<td valign="top">MEDIUMINT(size)</td>
<td valign="top">-8388608   to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may   be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">INT(size)</td>
<td valign="top">-2147483648   to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits   may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">BIGINT(size)</td>
<td valign="top">-9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis</td>
</tr>
<tr>
<td valign="top">FLOAT(size,d)</td>
<td valign="top">A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
<tr>
<td valign="top">DOUBLE(size,d)</td>
<td valign="top">A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
<tr>
<td valign="top">DECIMAL(size,d)</td>
<td valign="top">A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter</td>
</tr>
</tbody>
</table>
<p>*The integer types have an extra option called UNSIGNED. Normally, the integer goes from an negative to positive value. Adding the UNSIGNED attribute will move that range up so it starts at zero instead of a negative number.</p>
<p><strong>Date types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">DATE()</td>
<td valign="top">A   date. Format: YYYY-MM-DD<strong>Note:</strong> The supported range is from   &#8217;1000-01-01&#8242; to &#8217;9999-12-31&#8242;</td>
</tr>
<tr>
<td valign="top">DATETIME()</td>
<td valign="top">*A   date and time combination. Format: YYYY-MM-DD HH:MM:SS<strong>Note:</strong> The supported range is from   &#8217;1000-01-01 00:00:00&#8242; to &#8217;9999-12-31 23:59:59&#8242;</td>
</tr>
<tr>
<td valign="top">TIMESTAMP()</td>
<td valign="top">*A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (&#8217;1970-01-01 00:00:00&#8242; UTC). Format: YYYY-MM-DD HH:MM:SS<strong>Note:</strong> The supported range is from   &#8217;1970-01-01 00:00:01&#8242; UTC to &#8217;2038-01-09 03:14:07&#8242; UTC</td>
</tr>
<tr>
<td valign="top">TIME()</td>
<td valign="top">A   time. Format: HH:MM:SS<strong>Note:</strong> The supported range is from   &#8216;-838:59:59&#8242; to &#8217;838:59:59&#8242;</td>
</tr>
<tr>
<td valign="top">YEAR()</td>
<td valign="top">A   year in two-digit or four-digit format.<strong>Note:</strong> Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069</td>
</tr>
</tbody>
</table>
<p>*Even if DATETIME and TIMESTAMP return the same format, they work very differently. In an INSERT or UPDATE query, the TIMESTAMP automatically set itself to the current date and time. TIMESTAMP also accepts various formats, like YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Server Data Types</h2>
<p><strong>Character strings:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">char(n)</td>
<td valign="top">Fixed-length   character string. Maximum 8,000 characters</td>
<td valign="top">n</td>
</tr>
<tr>
<td valign="top">varchar(n)</td>
<td valign="top">Variable-length   character string. Maximum 8,000 characters</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">varchar(max)</td>
<td valign="top">Variable-length   character string. Maximum 1,073,741,824 characters</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">text</td>
<td valign="top">Variable-length   character string. Maximum 2GB of text data</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<p><strong>Unicode strings:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">nchar(n)</td>
<td valign="top">Fixed-length   Unicode data. Maximum 4,000 characters</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">nvarchar(n)</td>
<td valign="top">Variable-length   Unicode data. Maximum 4,000 characters</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">nvarchar(max)</td>
<td valign="top">Variable-length   Unicode data. Maximum 536,870,912 characters</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">ntext</td>
<td valign="top">Variable-length   Unicode data. Maximum 2GB of text data</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<p><strong>Binary types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">bit</td>
<td valign="top">Allows   0, 1, or NULL</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">binary(n)</td>
<td valign="top">Fixed-length   binary data. Maximum 8,000 bytes</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">varbinary(n)</td>
<td valign="top">Variable-length   binary data. Maximum 8,000 bytes</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">varbinary(max)</td>
<td valign="top">Variable-length   binary data. Maximum 2GB</td>
<td valign="top"></td>
</tr>
<tr>
<td valign="top">image</td>
<td valign="top">Variable-length   binary data. Maximum 2GB</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<p><strong>Number types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">tinyint</td>
<td valign="top">Allows   whole numbers from 0 to 255</td>
<td valign="top">1   byte</td>
</tr>
<tr>
<td valign="top">smallint</td>
<td valign="top">Allows   whole numbers between -32,768 and 32,767</td>
<td valign="top">2   bytes</td>
</tr>
<tr>
<td valign="top">int</td>
<td valign="top">Allows   whole numbers between -2,147,483,648 and 2,147,483,647</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">bigint</td>
<td valign="top">Allows   whole numbers between -9,223,372,036,854,775,808 and   9,223,372,036,854,775,807</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">decimal(p,s)</td>
<td valign="top">Fixed precision and scale numbers.Allows numbers from -10^38 +1 to 10^38 -1.The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0</td>
<td valign="top">5-17   bytes</td>
</tr>
<tr>
<td valign="top">numeric(p,s)</td>
<td valign="top">Fixed precision and scale numbers.Allows numbers from -10^38 +1 to 10^38 -1.The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0</td>
<td valign="top">5-17   bytes</td>
</tr>
<tr>
<td valign="top">smallmoney</td>
<td valign="top">Monetary   data from -214,748.3648 to 214,748.3647</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">money</td>
<td valign="top">Monetary   data from -922,337,203,685,477.5808 to 922,337,203,685,477.5807</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">float(n)</td>
<td valign="top">Floating precision number data from -1.79E + 308 to 1.79E + 308.The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.</td>
<td valign="top">4   or 8 bytes</td>
</tr>
<tr>
<td valign="top">real</td>
<td valign="top">Floating   precision number data from -3.40E + 38 to 3.40E + 38</td>
<td valign="top">4   bytes</td>
</tr>
</tbody>
</table>
<p><strong>Date types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="70%" valign="top"><strong>Description</strong></td>
<td width="10%" valign="top"><strong>Storage</strong></td>
</tr>
<tr>
<td valign="top">datetime</td>
<td valign="top">From   January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds</td>
<td valign="top">8   bytes</td>
</tr>
<tr>
<td valign="top">datetime2</td>
<td valign="top">From   January 1, 0001 and December 31, 9999 with an accuracy of 100 nanoseconds</td>
<td valign="top">6-8   bytes</td>
</tr>
<tr>
<td valign="top">smalldatetime</td>
<td valign="top">From   January 1, 1900 to June 6, 2079 with an accuracy of 1 minute</td>
<td valign="top">4   bytes</td>
</tr>
<tr>
<td valign="top">date</td>
<td valign="top">Store   a date only. From January 1, 0001 to December 31, 9999</td>
<td valign="top">3   bytes</td>
</tr>
<tr>
<td valign="top">time</td>
<td valign="top">Store   a time only to an accuracy of 100 nanoseconds</td>
<td valign="top">3-5   bytes</td>
</tr>
<tr>
<td valign="top">datetimeoffset</td>
<td valign="top">The   same as datetime2 with the addition of a time zone offset</td>
<td valign="top">8-10   bytes</td>
</tr>
<tr>
<td valign="top">timestamp</td>
<td valign="top">Stores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<p><strong>Other data types:</strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Data type</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">sql_variant</td>
<td valign="top">Stores   up to 8,000 bytes of data of various data types, except text, ntext, and   timestamp</td>
</tr>
<tr>
<td valign="top">uniqueidentifier</td>
<td valign="top">Stores   a globally unique identifier (GUID)</td>
</tr>
<tr>
<td valign="top">xml</td>
<td valign="top">Stores   XML formatted data. Maximum 2GB</td>
</tr>
<tr>
<td valign="top">cursor</td>
<td valign="top">Stores   a reference to a cursor used for database operations</td>
</tr>
<tr>
<td valign="top">table</td>
<td valign="top">Stores   a result-set for later processing</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Functions</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<p>SQL has many built-in functions for performing calculations on data.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Aggregate Functions</h2>
<p>SQL aggregate functions return a single value, calculated from values in a column.</p>
<p>Useful aggregate functions:</p>
<ul type="disc">
<li>AVG() &#8211; Returns the average value</li>
<li>COUNT() &#8211; Returns the number of rows</li>
<li>FIRST() &#8211; Returns the first value</li>
<li>LAST() &#8211; Returns the last value</li>
<li>MAX() &#8211; Returns the largest value</li>
<li>MIN() &#8211; Returns the smallest value</li>
<li>SUM() &#8211; Returns the sum</li>
</ul>
<hr size="1" noshade="noshade" />
<h2>SQL Scalar functions</h2>
<p>SQL scalar functions return a single value, based on the input value.</p>
<p>Useful scalar functions:</p>
<ul type="disc">
<li>UCASE() &#8211; Converts a field to upper case</li>
<li>LCASE() &#8211; Converts a field to lower case</li>
<li>MID() &#8211; Extract characters from a text field</li>
<li>LEN() &#8211; Returns the length of a text field</li>
<li>ROUND() &#8211; Rounds a numeric field to the      number of decimals specified</li>
<li>NOW() &#8211; Returns the current system date and      time</li>
<li>FORMAT() &#8211; Formats how a field is to be      displayed</li>
</ul>
<p><strong>Tip:</strong> The aggregate functions and the scalar functions will be explained in details in the next chapters.</p>
<h2><span style="color:#800000;">SQL AVG() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The AVG() Function</h2>
<p>The AVG() function returns the average value of a numeric column.</p>
<h3>SQL AVG() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT AVG(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL AVG() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the average value of the &#8220;OrderPrice&#8221; fields.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT AVG(OrderPrice) AS OrderAverage   FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>OrderAverage</strong></td>
</tr>
<tr>
<td>950</td>
</tr>
</tbody>
</table>
<p>Now we want to find the customers that have an OrderPrice value higher then the average OrderPrice value.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Customer FROM Orders<br />
WHERE OrderPrice&gt;(SELECT AVG(OrderPrice) FROM Orders)</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>Hansen</td>
</tr>
<tr>
<td>Nilsen</td>
</tr>
<tr>
<td>Jensen</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL COUNT() Function</span></h2>
<hr size="1" noshade="noshade" />The COUNT() function returns the number of rows that matches a specified criteria.</p>
<hr size="1" noshade="noshade" />
<h3>SQL COUNT(column_name) Syntax</h3>
<p>The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<h3>SQL COUNT(*) Syntax</h3>
<p>The COUNT(*) function returns the number of records in a table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(*) FROM table_name</td>
</tr>
</tbody>
</table>
<h3>SQL COUNT(DISTINCT column_name) Syntax</h3>
<p>The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(DISTINCT column_name)   FROM table_name</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> COUNT(DISTINCT) works with ORACLE and Microsoft SQL Server, but not with Microsoft Access.</p>
<hr size="1" noshade="noshade" />
<h2>SQL COUNT(column_name) Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to count the number of orders from &#8220;Customer Nilsen&#8221;.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(Customer) AS   CustomerNilsen FROM Orders<br />
WHERE Customer=&#8217;Nilsen&#8217;</td>
</tr>
</tbody>
</table>
<p>The result of the SQL statement above will be 2, because the customer Nilsen has made 2 orders in total:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>CustomerNilsen</strong></td>
</tr>
<tr>
<td>2</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL COUNT(*) Example</h2>
<p>If we omit the WHERE clause, like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(*) AS NumberOfOrders FROM   Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>NumberOfOrders</strong></td>
</tr>
<tr>
<td>6</td>
</tr>
</tbody>
</table>
<p>which is the total number of rows in the table.</p>
<hr size="1" noshade="noshade" />
<h2>SQL COUNT(DISTINCT column_name) Example</h2>
<p>Now we want to count the number of unique customers in the &#8220;Orders&#8221; table.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT COUNT(DISTINCT Customer) AS   NumberOfCustomers FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>NumberOfCustomers</strong></td>
</tr>
<tr>
<td>3</td>
</tr>
</tbody>
</table>
<p>which is the number of unique customers (Hansen, Nilsen, and Jensen) in the &#8220;Orders&#8221; table.</p>
<hr size="1" noshade="noshade" />
<h2><span style="color:#800000;">SQL FIRST() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The FIRST() Function</h2>
<p>The FIRST() function returns the first value of the selected column.</p>
<h3>SQL FIRST() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT FIRST(column_name) FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL FIRST() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the first value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT FIRST(OrderPrice) AS   FirstOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>FirstOrderPrice</strong></td>
</tr>
<tr>
<td>1000</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL LAST() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The LAST() Function</h2>
<p>The LAST() function returns the last value of the selected column.</p>
<h3>SQL LAST() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LAST(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL LAST() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the last value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LAST(OrderPrice) AS   LastOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>LastOrderPrice</strong></td>
</tr>
<tr>
<td>100</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL MAX() Function</span></h2>
<hr size="1" noshade="noshade" />
<h2>The MAX() Function</h2>
<p>The MAX() function returns the largest value of the selected column.</p>
<h3>SQL MAX() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MAX(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL MAX() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the largest value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MAX(OrderPrice) AS   LargestOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>LargestOrderPrice</strong></td>
</tr>
<tr>
<td>2000</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL MIN() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The MIN() Function</h2>
<p>The MIN() function returns the smallest value of the selected column.</p>
<h3>SQL MIN() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MIN(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL MIN() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the smallest value of the &#8220;OrderPrice&#8221; column.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MIN(OrderPrice) AS   SmallestOrderPrice FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>SmallestOrderPrice</strong></td>
</tr>
<tr>
<td>100</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL SUM() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The SUM() Function</h2>
<p>The SUM() function returns the total sum of a numeric column.</p>
<h3>SQL SUM() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT SUM(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL SUM() Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the sum of all &#8220;OrderPrice&#8221; fields&#8221;.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT SUM(OrderPrice) AS OrderTotal   FROM Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>OrderTotal</strong></td>
</tr>
<tr>
<td>5700</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL GROUP BY Statement</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<p>Aggregate functions often need an added GROUP BY statement.</p>
<hr size="1" noshade="noshade" />
<h2>The GROUP BY Statement</h2>
<p>The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.</p>
<h3>SQL GROUP BY Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name,   aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL GROUP BY Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find the total sum (total order) of each customer.</p>
<p>We will have to use the GROUP BY statement to group the customers.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM   Orders<br />
GROUP BY Customer</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>2000</td>
</tr>
<tr>
<td>Nilsen</td>
<td>1700</td>
</tr>
<tr>
<td>Jensen</td>
<td>2000</td>
</tr>
</tbody>
</table>
<p>Nice! Isn&#8217;t it? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let&#8217;s see what happens if we omit the GROUP BY statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM   Orders</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Nilsen</td>
<td>5700</td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Hansen</td>
<td>5700</td>
</tr>
<tr>
<td>Jensen</td>
<td>5700</td>
</tr>
<tr>
<td>Nilsen</td>
<td>5700</td>
</tr>
</tbody>
</table>
<p>The result-set above is not what we wanted.</p>
<p><strong>Explanation of why the above SELECT statement cannot be used:</strong> The SELECT statement above has two columns specified (Customer and SUM(OrderPrice). The &#8220;SUM(OrderPrice)&#8221; returns a single value (that is the total sum of the &#8220;OrderPrice&#8221; column), while &#8220;Customer&#8221; returns 6 values (one value for each row in the &#8220;Orders&#8221; table). This will therefore not give us the correct result. However, you have seen that the GROUP BY statement solves this problem.</p>
<hr size="1" noshade="noshade" />
<h2>GROUP BY More Than One Column</h2>
<p>We can also use the GROUP BY statement on more than one column, like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   Customer,OrderDate,SUM(OrderPrice) FROM Orders<br />
GROUP BY Customer,OrderDate</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL HAVING Clause</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The HAVING Clause</h2>
<p>The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.</p>
<h3>SQL HAVING Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT column_name,   aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name<br />
HAVING aggregate_function(column_name) operator value</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL HAVING Example</h2>
<p>We have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>O_Id</strong></td>
<td><strong>OrderDate</strong></td>
<td><strong>OrderPrice</strong></td>
<td><strong>Customer</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008/11/12</td>
<td>1000</td>
<td>Hansen</td>
</tr>
<tr>
<td>2</td>
<td>2008/10/23</td>
<td>1600</td>
<td>Nilsen</td>
</tr>
<tr>
<td>3</td>
<td>2008/09/02</td>
<td>700</td>
<td>Hansen</td>
</tr>
<tr>
<td>4</td>
<td>2008/09/03</td>
<td>300</td>
<td>Hansen</td>
</tr>
<tr>
<td>5</td>
<td>2008/08/30</td>
<td>2000</td>
<td>Jensen</td>
</tr>
<tr>
<td>6</td>
<td>2008/10/04</td>
<td>100</td>
<td>Nilsen</td>
</tr>
</tbody>
</table>
<p>Now we want to find if any of the customers have a total order of less than 2000.</p>
<p>We use the following SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM   Orders<br />
GROUP BY Customer<br />
HAVING SUM(OrderPrice)&lt;2000</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Nilsen</td>
<td>1700</td>
</tr>
</tbody>
</table>
<p>Now we want to find if the customers &#8220;Hansen&#8221; or &#8220;Jensen&#8221; have a total order of more than 1500.</p>
<p>We add an ordinary WHERE clause to the SQL statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT Customer,SUM(OrderPrice) FROM   Orders<br />
WHERE Customer=&#8217;Hansen&#8217; OR Customer=&#8217;Jensen&#8217;<br />
GROUP BY Customer<br />
HAVING SUM(OrderPrice)&gt;1500</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>Customer</strong></td>
<td><strong>SUM(OrderPrice)</strong></td>
</tr>
<tr>
<td>Hansen</td>
<td>2000</td>
</tr>
<tr>
<td>Jensen</td>
<td>2000</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL UCASE() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The UCASE() Function</h2>
<p>The UCASE() function converts the value of a field to uppercase.</p>
<h3>SQL UCASE() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT UCASE(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL UCASE() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the &#8220;LastName&#8221; and &#8220;FirstName&#8221; columns above, and convert the &#8220;LastName&#8221; column to uppercase.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT UCASE(LastName) as   LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>HANSEN</td>
<td>Ola</td>
</tr>
<tr>
<td>SVENDSON</td>
<td>Tove</td>
</tr>
<tr>
<td>PETTERSEN</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL LCASE() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The LCASE() Function</h2>
<p>The LCASE() function converts the value of a field to lowercase.</p>
<h3>SQL LCASE() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LCASE(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL LCASE() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the content of the &#8220;LastName&#8221; and &#8220;FirstName&#8221; columns above, and convert the &#8220;LastName&#8221; column to lowercase.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LCASE(LastName) as   LastName,FirstName FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
</tr>
<tr>
<td>hansen</td>
<td>Ola</td>
</tr>
<tr>
<td>svendson</td>
<td>Tove</td>
</tr>
<tr>
<td>pettersen</td>
<td>Kari</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL MID() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The MID() Function</h2>
<p>The MID() function is used to extract characters from a text field.</p>
<h3>SQL MID() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MID(column_name,start[,length])   FROM table_name</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Parameter</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required.   The field to extract characters from</td>
</tr>
<tr>
<td valign="top">start</td>
<td valign="top">Required.   Specifies the starting position (starts at 1)</td>
</tr>
<tr>
<td valign="top">length</td>
<td valign="top">Optional.   The number of characters to return. If omitted, the MID() function returns   the rest of the text</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL MID() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to extract the first four characters of the &#8220;City&#8221; column above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT MID(City,1,4) as SmallCity FROM   Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>SmallCity</strong></td>
</tr>
<tr>
<td>Sand</td>
</tr>
<tr>
<td>Sand</td>
</tr>
<tr>
<td>Stav</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL LEN() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The LEN() Function</h2>
<p>The LEN() function returns the length of the value in a text field.</p>
<h3>SQL LEN() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LEN(column_name) FROM   table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL LEN() Example</h2>
<p>We have the following &#8220;Persons&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>P_Id</strong></td>
<td><strong>LastName</strong></td>
<td><strong>FirstName</strong></td>
<td><strong>Address</strong></td>
<td><strong>City</strong></td>
</tr>
<tr>
<td>1</td>
<td>Hansen</td>
<td>Ola</td>
<td>Timoteivn   10</td>
<td>Sandnes</td>
</tr>
<tr>
<td>2</td>
<td>Svendson</td>
<td>Tove</td>
<td>Borgvn   23</td>
<td>Sandnes</td>
</tr>
<tr>
<td>3</td>
<td>Pettersen</td>
<td>Kari</td>
<td>Storgt   20</td>
<td>Stavanger</td>
</tr>
</tbody>
</table>
<p>Now we want to select the length of the values in the &#8220;Address&#8221; column above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT LEN(Address) as LengthOfAddress   FROM Persons</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>LengthOfAddress</strong></td>
</tr>
<tr>
<td>12</td>
</tr>
<tr>
<td>9</td>
</tr>
<tr>
<td>9</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL ROUND() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The ROUND() Function</h2>
<p>The ROUND() function is used to round a numeric field to the number of decimals specified.</p>
<h3>SQL ROUND() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT ROUND(column_name,decimals)   FROM table_name</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Parameter</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required.   The field to round.</td>
</tr>
<tr>
<td valign="top">decimals</td>
<td valign="top">Required.   Specifies the number of decimals to be returned.</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL ROUND() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000   g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000   g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000   g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the product name and the price rounded to the nearest integer.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT ProductName, ROUND(UnitPrice,0)   as UnitPrice FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>33</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>16</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL NOW() Function</span></h2>
<hr size="1" noshade="noshade" />
<h2>The NOW() Function</h2>
<p>The NOW() function returns the current system date and time.</p>
<h3>SQL NOW() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT NOW() FROM table_name</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL NOW() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000   g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000   g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000   g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the products and prices per today&#8217;s date.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT ProductName, UnitPrice, Now()   as PerDate FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>PerDate</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10.45</td>
<td>10/7/2008   11:25:02 AM</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>32.56</td>
<td>10/7/2008   11:25:02 AM</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>15.67</td>
<td>10/7/2008   11:25:02 AM</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL FORMAT() Function</span></h2>
<h1>
<hr size="1" noshade="noshade" /></h1>
<h2>The FORMAT() Function</h2>
<p>The FORMAT() function is used to format how a field is to be displayed.</p>
<h3>SQL FORMAT() Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT FORMAT(column_name,format) FROM   table_name</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%" valign="top"><strong>Parameter</strong></td>
<td width="80%" valign="top"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top">column_name</td>
<td valign="top">Required.   The field to be formatted.</td>
</tr>
<tr>
<td valign="top">format</td>
<td valign="top">Required.   Specifies the format.</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL FORMAT() Example</h2>
<p>We have the following &#8220;Products&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>Prod_Id</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>Unit</strong></td>
<td><strong>UnitPrice</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg</td>
<td>1000   g</td>
<td>10.45</td>
</tr>
<tr>
<td>2</td>
<td>Mascarpone</td>
<td>1000   g</td>
<td>32.56</td>
</tr>
<tr>
<td>3</td>
<td>Gorgonzola</td>
<td>1000   g</td>
<td>15.67</td>
</tr>
</tbody>
</table>
<p>Now we want to display the products and prices per today&#8217;s date (with today&#8217;s date displayed in the following format &#8220;YYYY-MM-DD&#8221;).</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT ProductName, UnitPrice,   FORMAT(Now(),&#8217;YYYY-MM-DD&#8217;) as PerDate<br />
FROM Products</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>ProductName</strong></td>
<td><strong>UnitPrice</strong></td>
<td><strong>PerDate</strong></td>
</tr>
<tr>
<td>Jarlsberg</td>
<td>10.45</td>
<td>2008-10-07</td>
</tr>
<tr>
<td>Mascarpone</td>
<td>32.56</td>
<td>2008-10-07</td>
</tr>
<tr>
<td>Gorgonzola</td>
<td>15.67</td>
<td>2008-10-07</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Quick Reference From W3Schools</span></h2>
<hr size="1" noshade="noshade" />
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="27%" valign="top"><strong>SQL Statement</strong></td>
<td width="73%" valign="top"><strong>Syntax</strong></td>
</tr>
<tr>
<td valign="top">AND   / OR</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
WHERE condition<br />
AND|OR condition</td>
</tr>
<tr>
<td valign="top">ALTER   TABLE</td>
<td valign="top">ALTER   TABLE table_name<br />
ADD column_name datatypeorALTER TABLE   table_name<br />
DROP COLUMN column_name</td>
</tr>
<tr>
<td valign="top">AS   (alias)</td>
<td valign="top">SELECT   column_name AS column_alias<br />
FROM table_nameorSELECT column_name<br />
FROM table_name  AS table_alias</td>
</tr>
<tr>
<td valign="top">BETWEEN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
BETWEEN value1 AND value2</td>
</tr>
<tr>
<td valign="top">CREATE   DATABASE</td>
<td valign="top">CREATE   DATABASE database_name</td>
</tr>
<tr>
<td valign="top">CREATE   TABLE</td>
<td valign="top">CREATE   TABLE table_name<br />
(<br />
column_name1 data_type,<br />
column_name2 data_type,<br />
column_name2 data_type,<br />
&#8230;<br />
)</td>
</tr>
<tr>
<td valign="top">CREATE   INDEX</td>
<td valign="top">CREATE   INDEX index_name<br />
ON table_name (column_name)orCREATE UNIQUE INDEX   index_name<br />
ON table_name (column_name)</td>
</tr>
<tr>
<td valign="top">CREATE   VIEW</td>
<td valign="top">CREATE   VIEW view_name AS<br />
SELECT column_name(s)<br />
FROM table_name<br />
WHERE condition</td>
</tr>
<tr>
<td valign="top">DELETE</td>
<td valign="top">DELETE   FROM table_name<br />
WHERE some_column=some_valueorDELETE FROM   table_name<br />
(<strong>Note: </strong>Deletes the entire table!!)DELETE * FROM   table_name<br />
(<strong>Note: </strong>Deletes the entire table!!)</td>
</tr>
<tr>
<td valign="top">DROP   DATABASE</td>
<td valign="top">DROP   DATABASE database_name</td>
</tr>
<tr>
<td valign="top">DROP   INDEX</td>
<td valign="top">DROP   INDEX table_name.index_name (SQL Server)<br />
DROP INDEX index_name ON table_name (MS Access)<br />
DROP INDEX index_name (DB2/Oracle)<br />
ALTER TABLE table_name<br />
DROP INDEX index_name (MySQL)</td>
</tr>
<tr>
<td valign="top">DROP   TABLE</td>
<td valign="top">DROP   TABLE table_name</td>
</tr>
<tr>
<td valign="top">GROUP   BY</td>
<td valign="top">SELECT   column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name</td>
</tr>
<tr>
<td valign="top">HAVING</td>
<td valign="top">SELECT   column_name, aggregate_function(column_name)<br />
FROM table_name<br />
WHERE column_name operator value<br />
GROUP BY column_name<br />
HAVING aggregate_function(column_name) operator value</td>
</tr>
<tr>
<td valign="top">IN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
WHERE column_name<br />
IN (value1,value2,..)</td>
</tr>
<tr>
<td valign="top">INSERT   INTO</td>
<td valign="top">INSERT   INTO table_name<br />
VALUES (value1, value2, value3,&#8230;.)<em>or</em>INSERT INTO   table_name<br />
(column1, column2, column3,&#8230;)<br />
VALUES (value1, value2, value3,&#8230;.)</td>
</tr>
<tr>
<td valign="top">INNER   JOIN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name1<br />
INNER JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">LEFT   JOIN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name1<br />
LEFT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">RIGHT   JOIN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name1<br />
RIGHT JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">FULL   JOIN</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name1<br />
FULL JOIN table_name2<br />
ON table_name1.column_name=table_name2.column_name</td>
</tr>
<tr>
<td valign="top">LIKE</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
WHERE column_name LIKE pattern</td>
</tr>
<tr>
<td valign="top">ORDER   BY</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
ORDER BY column_name [ASC|DESC]</td>
</tr>
<tr>
<td valign="top">SELECT</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT   *</td>
<td valign="top">SELECT   *<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT   DISTINCT</td>
<td valign="top">SELECT   DISTINCT column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">SELECT   INTO</td>
<td valign="top">SELECT   *<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_table_name<em>or</em>SELECT column_name(s)<br />
INTO new_table_name [IN externaldatabase]<br />
FROM old_table_name</td>
</tr>
<tr>
<td valign="top">SELECT   TOP</td>
<td valign="top">SELECT   TOP number|percent column_name(s)<br />
FROM table_name</td>
</tr>
<tr>
<td valign="top">TRUNCATE   TABLE</td>
<td valign="top">TRUNCATE   TABLE table_name</td>
</tr>
<tr>
<td valign="top">UNION</td>
<td valign="top">SELECT   column_name(s) FROM table_name1<br />
UNION<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
<tr>
<td valign="top">UNION   ALL</td>
<td valign="top">SELECT   column_name(s) FROM table_name1<br />
UNION ALL<br />
SELECT column_name(s) FROM table_name2</td>
</tr>
<tr>
<td valign="top">UPDATE</td>
<td valign="top">UPDATE   table_name<br />
SET column1=value, column2=value,&#8230;<br />
WHERE some_column=some_value</td>
</tr>
<tr>
<td valign="top">WHERE</td>
<td valign="top">SELECT   column_name(s)<br />
FROM table_name<br />
WHERE column_name operator value</td>
</tr>
</tbody>
</table>
<p><strong>Source : http://www.w3schools.com/sql/sql_quickref.asp</strong></p>
<h2><span style="color:#800000;">SQL Date Functions</span></h2>
<hr size="1" noshade="noshade" />
<h2>SQL Dates</h2>
<p>The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database.</p>
<p>As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated.</p>
<p>Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.</p>
<hr size="1" noshade="noshade" />
<h2>MySQL Date Functions</h2>
<p>The following table lists the most important built-in date functions in MySQL:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_now.asp">NOW()</a></td>
<td>Returns   the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_curdate.asp">CURDATE()</a></td>
<td>Returns   the current date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_curtime.asp">CURTIME()</a></td>
<td>Returns   the current time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date.asp">DATE()</a></td>
<td>Extracts   the date part of a date or date/time expression</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_extract.asp">EXTRACT()</a></td>
<td>Returns   a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_add.asp">DATE_ADD()</a></td>
<td>Adds   a specified time interval to a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_sub.asp">DATE_SUB()</a></td>
<td>Subtracts   a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datediff_mysql.asp">DATEDIFF()</a></td>
<td>Returns   the number of days between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_date_format.asp">DATE_FORMAT()</a></td>
<td>Displays   date/time data in different formats</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Server Date Functions</h2>
<p>The following table lists the most important built-in date functions in SQL Server:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="22%"><strong>Function</strong></td>
<td width="78%"><strong>Description</strong></td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_getdate.asp">GETDATE()</a></td>
<td>Returns   the current date and time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datepart.asp">DATEPART()</a></td>
<td>Returns   a single part of a date/time</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_dateadd.asp">DATEADD()</a></td>
<td>Adds   or subtracts a specified time interval from a date</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_datediff.asp">DATEDIFF()</a></td>
<td>Returns   the time between two dates</td>
</tr>
<tr>
<td><a href="http://www.w3schools.com/sql/func_convert.asp">CONVERT()</a></td>
<td>Displays   date/time data in different formats</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h2>SQL Date Data Types</h2>
<p><strong>MySQL</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul type="disc">
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>YEAR &#8211; format YYYY or YY</li>
</ul>
<p><strong>SQL Server</strong> comes with the following data types for storing a date or a date/time value in the database:</p>
<ul type="disc">
<li>DATE &#8211; format YYYY-MM-DD</li>
<li>DATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>SMALLDATETIME &#8211; format: YYYY-MM-DD HH:MM:SS</li>
<li>TIMESTAMP &#8211; format: a unique number</li>
</ul>
<p><strong>Note:</strong> The date types are chosen for a column when you create a new table in your database!</p>
<p>For an overview of all data types available, go to our complete <a href="http://www.w3schools.com/sql/sql_datatypes.asp">Data Types reference</a>.</p>
<hr size="1" noshade="noshade" />
<h2>SQL Working with Dates</h2>
<p>You can compare two dates easily if there is no time component involved!</p>
<p>Assume we have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>2</td>
<td>Camembert   Pierrot</td>
<td>2008-11-09</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone   Fabioli</td>
<td>2008-10-29</td>
</tr>
</tbody>
</table>
<p>Now we want to select the records with an OrderDate of &#8220;2008-11-11&#8243; from the table above.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE   OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>The result-set will look like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11</td>
</tr>
</tbody>
</table>
<p>Now, assume that the &#8220;Orders&#8221; table looks like this (notice the time component in the &#8220;OrderDate&#8221; column):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td width="20%"><strong>OrderId</strong></td>
<td width="45%"><strong>ProductName</strong></td>
<td width="35%"><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Geitost</td>
<td>2008-11-11   13:23:44</td>
</tr>
<tr>
<td>2</td>
<td>Camembert   Pierrot</td>
<td>2008-11-09   15:45:21</td>
</tr>
<tr>
<td>3</td>
<td>Mozzarella   di Giovanni</td>
<td>2008-11-11   11:12:01</td>
</tr>
<tr>
<td>4</td>
<td>Mascarpone   Fabioli</td>
<td>2008-10-29   14:56:59</td>
</tr>
</tbody>
</table>
<p>If we use the same SELECT statement as above:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT * FROM Orders WHERE   OrderDate=&#8217;2008-11-11&#8242;</td>
</tr>
</tbody>
</table>
<p>we will get no result! This is because the query is looking only for dates with no time portion.</p>
<p><strong>Tip:</strong> If you want to keep your queries simple and easy to maintain, do not allow time components in your dates!</p>
<h2><span style="color:#800000;">SQL Server GETDATE() Function</span></h2>
<hr size="1" noshade="noshade" /><a href="http://www.w3schools.com/sql/sql_dates.asp">SQL Server Date Functions</a></p>
<hr size="1" noshade="noshade" />
<h2>Definition and Usage</h2>
<p>The GETDATE() function returns the current date and time from the SQL Server.</p>
<h3>Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>GETDATE()</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h3>Example</h3>
<p>The following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT GETDATE() AS CurrentDateTime</td>
</tr>
</tbody>
</table>
<p>will result in something like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>CurrentDateTime</strong></td>
</tr>
<tr>
<td>2008-11-11   12:45:34.243</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The time part above goes all the way to milliseconds.</p>
<h3>Example</h3>
<p>The following SQL creates an &#8220;Orders&#8221; table with a datetime column (OrderDate):</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>CREATE TABLE Orders<br />
(<br />
OrderId int NOT NULL PRIMARY KEY,<br />
ProductName varchar(50) NOT NULL,<br />
OrderDate datetime NOT NULL DEFAULT GETDATE()<br />
)</td>
</tr>
</tbody>
</table>
<p>Notice that the OrderDate column specifies GETDATE() as the default value. As a result, when you insert a row into the table, the current date and time are automatically inserted into the column.</p>
<p>Now we want to insert a record into the &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>INSERT INTO Orders (ProductName)   VALUES (&#8216;Jarlsberg Cheese&#8217;)</td>
</tr>
</tbody>
</table>
<p>The &#8220;Orders&#8221; table will now look something like this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>OrderId</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg   Cheese</td>
<td>2008-11-11   13:23:44.657</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Server DATEPART() Function</span></h2>
<hr size="1" noshade="noshade" /><a href="http://www.w3schools.com/sql/sql_dates.asp">SQL Server Date Functions</a></p>
<hr size="1" noshade="noshade" />
<h2>Definition and Usage</h2>
<p>The DATEPART() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.</p>
<h3>Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DATEPART(datepart,date)</td>
</tr>
</tbody>
</table>
<p>Where date is a valid date expression and datepart can be one of the following:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>datepart</strong></td>
<td><strong>Abbreviation</strong></td>
</tr>
<tr>
<td>year</td>
<td>yy,   yyyy</td>
</tr>
<tr>
<td>quarter</td>
<td>qq,   q</td>
</tr>
<tr>
<td>month</td>
<td>mm,   m</td>
</tr>
<tr>
<td>dayofyear</td>
<td>dy,   y</td>
</tr>
<tr>
<td>day</td>
<td>dd,   d</td>
</tr>
<tr>
<td>week</td>
<td>wk,   ww</td>
</tr>
<tr>
<td>weekday</td>
<td>dw,   w</td>
</tr>
<tr>
<td>hour</td>
<td>hh</td>
</tr>
<tr>
<td>minute</td>
<td>mi,   n</td>
</tr>
<tr>
<td>second</td>
<td>ss,   s</td>
</tr>
<tr>
<td>millisecond</td>
<td>ms</td>
</tr>
<tr>
<td>microsecond</td>
<td>mcs</td>
</tr>
<tr>
<td>nanosecond</td>
<td>ns</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h3>Example</h3>
<p>Assume we have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>OrderId</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg   Cheese</td>
<td>2008-11-11   13:23:44.657</td>
</tr>
</tbody>
</table>
<p>The following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT DATEPART(yyyy,OrderDate) AS   OrderYear,<br />
DATEPART(mm,OrderDate) AS OrderMonth,<br />
DATEPART(dd,OrderDate) AS OrderDay,<br />
FROM Orders<br />
WHERE OrderId=1</td>
</tr>
</tbody>
</table>
<p>will result in this:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>OrderYear</strong></td>
<td><strong>OrderMonth</strong></td>
<td><strong>OrderDay</strong></td>
</tr>
<tr>
<td>2008</td>
<td>11</td>
<td>11</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Server DATEADD() Function</span></h2>
<hr size="1" noshade="noshade" /><a href="http://www.w3schools.com/sql/sql_dates.asp">SQL Server Date Functions</a></p>
<hr size="1" noshade="noshade" />
<h2>Definition and Usage</h2>
<p>The DATEADD() function is adds or subtracts a specified time interval from a date.</p>
<h3>Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DATEADD(datepart,number,date)</td>
</tr>
</tbody>
</table>
<p>Where date is a valid date expression and number is the number of interval you want to add. The number can either be positive, for dates in the future, or negative, for dates in the past.</p>
<p>datepart can be one of the following:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>datepart</strong></td>
<td><strong>Abbreviation</strong></td>
</tr>
<tr>
<td>year</td>
<td>yy,   yyyy</td>
</tr>
<tr>
<td>quarter</td>
<td>qq,   q</td>
</tr>
<tr>
<td>month</td>
<td>mm,   m</td>
</tr>
<tr>
<td>dayofyear</td>
<td>dy,   y</td>
</tr>
<tr>
<td>day</td>
<td>dd,   d</td>
</tr>
<tr>
<td>week</td>
<td>wk,   ww</td>
</tr>
<tr>
<td>weekday</td>
<td>dw,   w</td>
</tr>
<tr>
<td>hour</td>
<td>hh</td>
</tr>
<tr>
<td>minute</td>
<td>mi,   n</td>
</tr>
<tr>
<td>second</td>
<td>ss,   s</td>
</tr>
<tr>
<td>millisecond</td>
<td>ms</td>
</tr>
<tr>
<td>microsecond</td>
<td>mcs</td>
</tr>
<tr>
<td>nanosecond</td>
<td>ns</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h3>Example</h3>
<p>Assume we have the following &#8220;Orders&#8221; table:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>OrderId</strong></td>
<td><strong>ProductName</strong></td>
<td><strong>OrderDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>Jarlsberg   Cheese</td>
<td>2008-11-11   13:23:44.657</td>
</tr>
</tbody>
</table>
<p>Now we want to add 45 days to the &#8220;OrderDate&#8221;, to find the payment date.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   OrderId,DATEADD(day,45,OrderDate) AS OrderPayDate<br />
FROM Orders</td>
</tr>
</tbody>
</table>
<p>Result:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>OrderId</strong></td>
<td><strong>OrderPayDate</strong></td>
</tr>
<tr>
<td>1</td>
<td>2008-12-26   13:23:44.657</td>
</tr>
</tbody>
</table>
<h2><span style="color:#800000;">SQL Server DATEDIFF() Function</span></h2>
<hr size="1" noshade="noshade" /><a href="http://www.w3schools.com/sql/sql_dates.asp">SQL Server Date Functions</a></p>
<hr size="1" noshade="noshade" />
<h2>Definition and Usage</h2>
<p>The DATEDIFF() function returns the time between two dates.</p>
<h3>Syntax</h3>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>DATEDIFF(datepart,startdate,enddate)</td>
</tr>
</tbody>
</table>
<p>Where startdate and enddate are valid date expressions and datepart can be one of the following:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td><strong>datepart</strong></td>
<td><strong>Abbreviation</strong></td>
</tr>
<tr>
<td>year</td>
<td>yy,   yyyy</td>
</tr>
<tr>
<td>quarter</td>
<td>qq,   q</td>
</tr>
<tr>
<td>month</td>
<td>mm,   m</td>
</tr>
<tr>
<td>dayofyear</td>
<td>dy,   y</td>
</tr>
<tr>
<td>day</td>
<td>dd,   d</td>
</tr>
<tr>
<td>week</td>
<td>wk,   ww</td>
</tr>
<tr>
<td>weekday</td>
<td>dw,   w</td>
</tr>
<tr>
<td>hour</td>
<td>hh</td>
</tr>
<tr>
<td>minute</td>
<td>mi,   n</td>
</tr>
<tr>
<td>second</td>
<td>ss,   s</td>
</tr>
<tr>
<td>millisecond</td>
<td>ms</td>
</tr>
<tr>
<td>microsecond</td>
<td>mcs</td>
</tr>
<tr>
<td>nanosecond</td>
<td>ns</td>
</tr>
</tbody>
</table>
<hr size="1" noshade="noshade" />
<h3>Example</h3>
<p>Now we want to get the number of days between two dates.</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   DATEDIFF(day,&#8217;2008-06-05&#8242;,&#8217;2008-08-05&#8242;) AS DiffDate</td>
</tr>
</tbody>
</table>
<p>Result:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>DiffDate</strong></td>
</tr>
<tr>
<td>61</td>
</tr>
</tbody>
</table>
<h3>Example</h3>
<p>Now we want to get the number of days between two dates (notice that the second date is &#8220;earlier&#8221; than the first date, and will result in a negative number).</p>
<p>We use the following SELECT statement:</p>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>SELECT   DATEDIFF(day,&#8217;2008-08-05&#8242;,&#8217;2008-06-05&#8242;) AS DiffDate</td>
</tr>
</tbody>
</table>
<p>Result:</p>
<table border="1" cellspacing="0" cellpadding="0" width="50%">
<tbody>
<tr>
<td><strong>DiffDate</strong></td>
</tr>
<tr>
<td>-61</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=167&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/07/learn-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to Datawarehouse</title>
		<link>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse-2/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse-2/#comments</comments>
		<pubDate>Thu, 07 May 2009 12:13:19 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[DWH]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=164</guid>
		<description><![CDATA[INTRODUCTION TO DATA WAREHOUSE DataWarehouse: Data warehouse is record of an enterprise&#8217;s past transactional and operational information, stored in a database designed to favour efficient data analysis and reporting (especially OLAP). Data warehousing is not meant for current &#8220;live&#8221; data. Data warehouses often hold large amounts of information which are sometimes subdivided into smaller logical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=164&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;">INTRODUCTION TO DATA WAREHOUSE</h2>
<p><strong><img class="aligncenter size-full wp-image-165" title="data-warehousing1" src="http://ramkarthick.files.wordpress.com/2009/05/data-warehousing1.jpg?w=500" alt="data-warehousing1"   /></strong></p>
<p><strong>DataWarehouse: </strong></p>
<p>Data warehouse is record of an enterprise&#8217;s past transactional and operational information, stored in a database designed to favour efficient data analysis and reporting (especially OLAP).</p>
<p><a href="http://www.managementupdate.info/" target="_top">Data warehousing</a> is not meant for current &#8220;live&#8221; data. Data warehouses often hold large amounts of information which are sometimes subdivided into smaller logical units called dependent data marts.</p>
<p>Usually, two basic ideas guide the creation of a data warehouse:</p>
<ul>
<li>Integration of data from distributed and differently structured databases, which facilitates a global overview and comprehensive analysis in the data warehouse.</li>
<li>Separation of data used in daily operations</li>
</ul>
<p>from data used in the <a href="http://www.managementupdate.info/#" target="_top">data warehouse</a> for purposes of reporting, decision support, analysis and controlling.Periodically, one imports data from enterprise resource planning (ERP ) systems and other related business software systems into the data warehouse for further processing. It is common practice to &#8220;stage&#8221; data prior to merging it into a data warehouse. In this sense, to &#8220;stage data&#8221; means to queue it for preprocessing, usually with an ETL tool. The preprocessing program reads the staged data (often a business&#8217;s primary OLTP databases), performs qualitative preprocessing or filtering (including denormalization, if deemed necessary), and writes it into the warehouse.</p>
<p>A database designed to support decision making in an organization. Data from the production databases are copied to the data warehouse so that queries can be performed without disturbing the performance or the stability of the production systems.Data storage of consolidated information dedicated to easely and quickly provide simple or pre-aggregated data for analysis</p>
<p><a href="http://www.e-plusconsulting.com/DW_Concepts/Glossary/glossary.html">www.e-plusconsulting.com/DW_Concepts/Glossary/glossary.html</a></p>
<p>A data warehouse is, primarily, a record of an enterprise&#8217;s past transactional and operational information, stored in a database designed to favour efficient data analysis and reporting (especially OLAP). Data warehousing is not meant for current, &#8220;live&#8221; data.</p>
<p><strong> </strong></p>
<p><span style="color:#800000;"><strong>Data Marts</strong></span></p>
<p>Data warehouses can become enormous with hundreds of gigabytes of transactions. As a result, subsets, known as &#8220;data marts,&#8221; are often created for just one department or product line.</p>
<p><strong> </strong></p>
<p><strong><span style="color:#800000;">ETL</span><br />
</strong>Data Warehouse acquisition processes of Extracting, Transforming (or Transporting) and Loading (ETL) data from source systems into the data warehouse.</p>
<p><a href="http://www.orafaq.com/glossary/faqglose.htm">www.orafaq.com/glossary/faqglose.htm</a></p>
<p>Three database functions that are combined into one tool to pull data out of source databases and place it into target databases. ETL is used to migrate data from databases to others, to form data marts and data warehouses and also to convert databases from one format or type to another.</p>
<p><a href="http://www.informatica.com/solutions/resource_center/glossary/default.htm">www.informatica.com/solutions/resource_center/glossary/default.htm</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=164&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/05/data-warehousing1.jpg" medium="image">
			<media:title type="html">data-warehousing1</media:title>
		</media:content>
	</item>
		<item>
		<title>DBA FAQs</title>
		<link>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse/#comments</comments>
		<pubDate>Thu, 07 May 2009 11:50:28 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[Interview Questions]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=159</guid>
		<description><![CDATA[DBA INTERVIEW QUESTIONS What is RDBMS? Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=159&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;"><strong><span style="color:#000000;">DBA INTERVIEW QUESTIONS </span><br />
</strong></p>
<p style="text-align:justify;"><strong>What is RDBMS?</strong><br />
Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Interdependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage.</p>
<p style="text-align:justify;"><strong>What is normalization?</strong></p>
<p style="text-align:justify;">Database normalization is a data design and organization process applied to data structures based on rules that help build relational databases. In relational database design, the process of organizing data to minimize redundancy. Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.</p>
<p style="text-align:justify;"><strong>What are different normalization forms?</strong></p>
<p style="text-align:justify;"><strong><em>1NF: Eliminate Repeating Groups</em></strong><br />
Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.<br />
<strong><em>2NF: Eliminate Redundant Data</em></strong><br />
If an attribute depends on only part of a multi-valued key, remove it to a separate table.<br />
<strong><em>3NF: Eliminate Columns Not Dependent On Key </em></strong><br />
If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key<br />
<strong><em>BCNF: Boyce-Codd Normal Form</em></strong><br />
If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.<br />
<strong><em>4NF: Isolate Independent Multiple Relationships</em></strong><br />
No table may contain two or more 1:n or n:m relationships that are not directly related.<br />
<strong><em>5NF: Isolate Semantically Related Multiple Relationships </em></strong><br />
There may be practical constrains on information that justify separating logically related many-to-many relationships.<br />
<strong><em>ONF: Optimal Normal Form</em></strong><br />
A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.<br />
<strong><em>DKNF: Domain-Key Normal Form</em></strong><br />
A model free from all modification anomalies.</p>
<p style="text-align:justify;">Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.</p>
<p style="text-align:justify;"><strong>What is Stored Procedure?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.<br />
e.g. sp_helpdb, sp_renamedb, sp_depends etc.</p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong>What is Trigger?</strong><br />
A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS.Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; the DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.<br />
<em>Nested Trigger: </em>A trigger can also contain INSERT, UPDATE and DELETE logic within itself, so when the trigger is fired because of data modification it can also cause another data modification, thereby firing another trigger. A trigger that contains data modification logic within itself is called a nested trigger.</p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong>What is View?</strong><br />
A simple view can be thought of as a subset of a table. It can be used for retrieving data, as well as updating or deleting rows. Rows updated or deleted in the view are updated or deleted in the table the view was created with. It should also be noted that as data in the original table changes, so does data in the view, as views are the way to look at part of the original table. The results of using a view are not permanently stored in the database. The data accessed through a view is actually constructed using standard T-SQL select command and can come from one to many different base tables or even other views.</p>
<p style="text-align:justify;"><strong>What is Index?</strong></p>
<p style="text-align:justify;">An index is a physical structure containing pointers to the data. Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application. A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance.</p>
<p style="text-align:justify;"><em>Clustered indexes</em> define the physical sorting of a database table&#8217;s rows in the storage media. For this reason, each database table may have only one clustered index.<br />
<em>Non-clustered indexes</em> are created outside of the database table and contain a sorted list of references to the table itself.</p>
<p style="text-align:justify;"><strong>What is the difference between clustered and a non-clustered index?</strong><br />
A <em>clustered index</em> is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.</p>
<p style="text-align:justify;">A <em>nonclustered index</em> is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.</p>
<p style="text-align:justify;"><strong>What are the different index configurations a table can have?</strong><br />
A table can have one of the following index configurations:</p>
<p style="text-align:justify;">No indexes<br />
A clustered index<br />
A clustered index and many nonclustered indexes<br />
A nonclustered index<br />
Many nonclustered indexes</p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong>What are cursors?</strong><br />
Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time. In order to work with a cursor we need to perform some steps in the following order:</p>
<p style="text-align:justify;">Declare cursor<br />
Open cursor<br />
Fetch row from the cursor<br />
Process fetched row<br />
Close cursor<br />
Deallocate cursor</p>
<p style="text-align:justify;"><strong>What is the use of DBCC commands?</strong><br />
DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks.E.g. DBCC CHECKDB &#8211; Ensures that tables in the db and the indexes are correctly linked.<br />
DBCC CHECKALLOC &#8211; To check that all pages in a db are correctly allocated.<br />
DBCC CHECKFILEGROUP &#8211; Checks all tables file group for any damage.</p>
<p style="text-align:justify;"><strong>What is a Linked Server?</strong></p>
<p style="text-align:justify;">Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. With a linked server, you can create very clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data.<br />
Storped Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server.</p>
<p style="text-align:justify;"><strong>What is Collation?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>Collation refers to a set of rules that determine how data is sorted and compared. Character data is sorted using rules that define the correct character sequence, with options for specifying case-sensitivity, accent marks, kana character types and character width.</p>
<p style="text-align:justify;"><strong>What are different type of Collation Sensitivity?</strong></p>
<p style="text-align:justify;"><em>Case sensitivity</em><br />
A and a, B and b, etc.</p>
<p style="text-align:justify;"><em>Accent sensitivity</em><br />
a and á, o and ó, etc.</p>
<p style="text-align:justify;"><em>Kana Sensitivity</em><br />
When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive.</p>
<p style="text-align:justify;"><em>Width sensitivity</em><br />
When a single-byte character (half-width) and the same character when represented as a double-byte character (full-width) are treated differently then it is width sensitive.</p>
<p style="text-align:justify;"><strong>What&#8217;s the difference between a primary key and a unique key?</strong><br />
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn&#8217;t allow NULLs, but unique key allows one NULL only.</p>
<p style="text-align:justify;"><strong>How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?</strong><br />
One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships.<br />
One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.<br />
Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.</p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong>What is a NOLOCK?</strong><br />
Using the NOLOCK query optimiser hint is generally considered good practice in order to improve concurrency on a busy system. When the NOLOCK hint is included in a SELECT statement, no locks are taken when data is read. The result is a Dirty Read, which means that another process could be updating the data at the exact time you are reading it. There are no guarantees that your query will retrieve the most recent data. The advantage to performance is that your reading of data will not block updates from taking place, and updates will not block your reading of data. SELECT statements take Shared (Read) locks. This means that multiple SELECT statements are allowed simultaneous access, but other processes are blocked from modifying the data. The updates will queue until all the reads have completed, and reads requested after the update will wait for the updates to complete. The result to your system is delay(blocking).</p>
<p style="text-align:justify;"><strong>What is difference between DELETE &amp; TRUNCATE commands?</strong><br />
Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.</p>
<p style="text-align:justify;"><strong><em>TRUNCATE</em></strong><br />
TRUNCATE is faster and uses fewer system and transaction log resources than DELETE.<br />
TRUNCATE removes the data by deallocating the data pages used to store the table&#8217;s data, and only the page deallocations are recorded in the transaction log.<br />
TRUNCATE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column.<br />
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint.<br />
Because TRUNCATE TABLE is not logged, it cannot activate a trigger.<br />
TRUNCATE can not be Rolled back using logs.<br />
TRUNCATE is DDL Command.<br />
TRUNCATE Resets identity of the table.</p>
<p style="text-align:justify;"><strong><em>DELETE</em></strong><br />
DELETE removes rows one at a time and records an entry in the transaction log for each deleted row.<br />
If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.<br />
DELETE Can be used with or without a WHERE clause<br />
DELETE Activates Triggers.<br />
DELETE Can be Rolled back using logs.<br />
DELETE is DML Command.<br />
DELETE does not reset identity of the table.</p>
<p style="text-align:justify;"><strong>Difference between Function and Stored Procedure?</strong><br />
UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.<br />
UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.<br />
Inline UDF&#8217;s can be though of as views that take parameters and can be used in JOINs and other Rowset operations.</p>
<p style="text-align:justify;"><strong>When is the use of UPDATE_STATISTICS command?</strong><br />
This command is basically used when a large processing of data has occurred. If a large amount of deletions any modification or Bulk Copy into the tables has occurred, it has to update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly.</p>
<p style="text-align:justify;"><strong>What types of Joins are possible with Sql Server?</strong><br />
Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.<br />
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.</p>
<p style="text-align:justify;"><strong>What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?</strong><br />
Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query. HAVING criteria is applied after the the grouping of rows has occurred.</p>
<p style="text-align:justify;"><strong>What is sub-query? Explain properties of sub-query.</strong><br />
Sub-queries are often referred to as sub-selects, as they allow a SELECT statement to be executed arbitrarily within the body of another SQL statement. A sub-query is executed by enclosing it in a set of parentheses. Sub-queries are generally used to return a single row as an atomic value, though they may be used to compare values against multiple rows with the IN keyword.</p>
<p style="text-align:justify;">A subquery is a SELECT statement that is nested within another T-SQL statement. A subquery SELECT statement if executed independently of the T-SQL statement, in which it is nested, will return a result set. Meaning a subquery SELECT statement can standalone and is not depended on the statement in which it is nested. A subquery SELECT statement can return any number of values, and can be found in, the column list of a SELECT statement, a FROM, GROUP BY, HAVING, and/or ORDER BY clauses of a T-SQL statement. A Subquery can also be used as a parameter to a function call. Basically a subquery can be used anywhere an expression can be used.</p>
<p style="text-align:justify;"><strong><em>Properties of Sub-Query</em></strong><br />
A subquery must be enclosed in the parenthesis.<br />
A subquery must be put in the right hand of the comparison operator, and<br />
A subquery cannot contain a ORDER-BY clause.<br />
A query can contain more than one sub-queries.</p>
<p style="text-align:justify;"><strong>What are types of sub-queries?</strong><br />
Single-row subquery, where the subquery returns only one row.<br />
Multiple-row subquery, where the subquery returns multiple rows,.and<br />
Multiple column subquery, where the subquery returns multiple columns.</p>
<p style="text-align:justify;"><strong> </strong></p>
<p style="text-align:justify;"><strong>What is SQL Profiler?</strong><br />
SQL Profiler is a graphical tool that allows system administrators to monitor events in an instance of Microsoft SQL Server. You can capture and save data about each event to a file or SQL Server table to analyze later. For example, you can monitor a production environment to see which stored procedures are hampering performance by executing too slowly.</p>
<p style="text-align:justify;">Use SQL Profiler to monitor only the events in which you are interested. If traces are becoming too large, you can filter them based on the information you want, so that only a subset of the event data is collected. Monitoring too many events adds overhead to the server and the monitoring process and can cause the trace file or trace table to grow very large, especially when the monitoring process takes place over a long period of time.</p>
<p style="text-align:justify;"><strong>What is User Defined Functions?</strong><br />
User-Defined Functions allow to define its own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type.</p>
<p style="text-align:justify;"><strong>What kind of User-Defined Functions can be created?</strong><br />
There are three types of User-Defined functions in SQL Server 2000 and they are Scalar, Inline Table-Valued and Multi-statement Table-valued.</p>
<p style="text-align:justify;"><em><strong>Scalar User-Defined Function</strong></em><br />
A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value.</p>
<p style="text-align:justify;"><em><strong>Inline Table-Value User-Defined Function</strong></em><br />
An Inline Table-Value user-defined function returns a table data type and is an exceptional alternative to a view as the user-defined function can pass parameters into a T-SQL select command and in essence provide us with a parameterized, non-updateable view of the underlying tables.</p>
<p style="text-align:justify;"><em><strong>Multi-statement Table-Value User-Defined Function</strong></em><br />
A Multi-Statement Table-Value user-defined function returns a table and is also an exceptional alternative to a view as the function can support multiple T-SQL statements to build the final result where the view is limited to a single SELECT statement. Also, the ability to pass parameters into a T-SQL select command or a group of them gives us the capability to in essence create a parameterized, non-updateable view of the data in the underlying tables. Within the create function command you must define the table structure that is being returned. After creating this type of user-defined function, It can be used in the FROM clause of a T-SQL command unlike the behavior found when using a stored procedure which can also return record sets.</p>
<p style="text-align:justify;"><strong>Which TCP/IP port does SQL Server run on? How can it be changed?</strong><br />
SQL Server runs on port 1433. It can be changed from the Network Utility TCP/IP properties -&gt; Port number.both on client and the server.</p>
<p style="text-align:justify;"><strong>What are the authentication modes in SQL Server? How can it be changed?</strong><br />
Windows mode and mixed mode (SQL &amp; Windows).</p>
<p style="text-align:justify;">To change authentication mode in SQL Server click Start, Programs, Microsoft SQL Server and click SQL Enterprise Manager to run SQL Enterprise Manager from the Microsoft SQL Server program group. Select the server then from the Tools menu select SQL Server Configuration Properties, and choose the Security page.</p>
<p style="text-align:justify;"><strong>Where are SQL server users names and passwords are stored in sql server?</strong><br />
They get stored in master db in the sysxlogins table.</p>
<p style="text-align:justify;"><strong>Which command using Query Analyzer will give you the version of SQL server and operating system?</strong><strong> </strong><br />
<code>SELECT </code><code>SERVERPROPERTY</code><code>(</code><code>'productversion'</code><code>), </code><code>SERVERPROPERTY </code><code>(</code><code>'productlevel'</code><code>), </code></p>
<p style="text-align:justify;"><strong>What is SQL server agent?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts.</p>
<p style="text-align:justify;"><strong>Can a stored procedure call itself or recursive stored procedure? How many level SP nesting possible?</strong><br />
Yes. Because Transact-SQL supports recursion, you can write stored procedures that call themselves. Recursion can be defined as a method of problem solving wherein the solution is arrived at by repetitively applying it to subsets of the problem. A common application of recursive logic is to perform numeric computations that lend themselves to repetitive evaluation by the same processing steps. Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate. You can nest stored procedures and managed code references up to 32 levels.</p>
<p style="text-align:justify;"><strong>What is @@ERROR?</strong><br />
The @@ERROR automatic variable returns the error code of the last Transact-SQL statement. If there was no error, @@ERROR returns zero. Because @@ERROR is reset after each Transact-SQL statement, it must be saved to a variable if it is needed to process it further after checking it.</p>
<p style="text-align:justify;"><strong>What is Raiseerror?</strong><strong> </strong><br />
Stored procedures report errors to client applications via the RAISERROR command. RAISERROR doesn&#8217;t change the flow of a procedure; it merely displays an error message, sets the @@ERROR automatic variable, and optionally writes the message to the SQL Server error log and the NT application event log.</p>
<p style="text-align:justify;"><strong>What is log shipping?</strong><br />
Log shipping is the process of automating the backup of database and transaction log files on a production SQL server, and then restoring them onto a standby server. Enterprise Editions only supports log shipping. In log shipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db can be used this as the Disaster Recovery plan. The key feature of log shipping is that is will automatically backup transaction logs throughout the day and automatically restore them on the standby server at defined interval.</p>
<p style="text-align:justify;"><strong>What is the difference between a local and a global variable?</strong><br />
A <em>local temporary </em>table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement.</p>
<p style="text-align:justify;">A <em>global temporary</em> table remains in the database permanently, but the rows exist only within a given connection. When connection are closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.</p>
<p style="text-align:justify;"><strong>What command do we use to rename a db? </strong><br />
sp_renamedb &#8216;oldname&#8217; , &#8216;newname&#8217;<br />
If someone is using db it will not accept sp_renmaedb. In that case first bring db to single user using sp_dboptions. Use sp_renamedb to rename database. Use sp_dboptions to bring database to multi user mode.</p>
<p style="text-align:justify;"><strong>What is sp_configure commands and set commands?</strong><br />
Use sp_configure to display or change server-level settings. To change database-level settings, use ALTER DATABASE. To change settings that affect only the current user session, use the SET statement.</p>
<p style="text-align:justify;"><strong>What are the different types of replication? Explain.</strong><br />
The SQL Server 2000-supported replication types are as follows:</p>
<p style="text-align:justify;">Transactional</p>
<p style="text-align:justify;">Snapshot</p>
<p style="text-align:justify;">Merge</p>
<p style="text-align:justify;"><strong><em>Snapshot replication</em></strong> distributes data exactly as it appears at a specific moment in time and does not monitor for updates to the data. Snapshot replication is best used as a method for replicating data that changes infrequently or where the most up-to-date values (low latency) are not a requirement. When synchronization occurs, the entire snapshot is generated and sent to Subscribers.</p>
<p style="text-align:justify;"><strong><em>Transactional replication</em></strong>, an initial snapshot of data is applied at Subscribers, and then when data modifications are made at the Publisher, the individual transactions are captured and propagated to Subscribers.</p>
<p style="text-align:justify;"><strong><em>Merge replication</em></strong> is the process of distributing data from Publisher to Subscribers, allowing the Publisher and Subscribers to make updates while connected or disconnected, and then merging the updates between sites when they are connected.</p>
<p style="text-align:justify;"><strong>What are the OS services that the SQL Server installation adds?</strong><br />
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)</p>
<p style="text-align:justify;"><strong>What are three SQL keywords used to change or set someone&#8217;s permissions?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>GRANT, DENY, and REVOKE.</p>
<p style="text-align:justify;"><strong>What does it mean to have quoted_identifier on? What are the implications of having it off?</strong><br />
When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers.</p>
<p style="text-align:justify;"><strong>What is the STUFF function and how does it differ from the REPLACE function?</strong><strong> </strong><br />
<strong>STUFF</strong> function to overwrite existing characters. Using this syntax, STUFF(string_expression, start, length, replacement_characters), string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string.<br />
<strong>REPLACE</strong> function to replace existing characters of all occurance. Using this syntax REPLACE(string_expression, search_string, replacement_string), where every incidence of search_string found in the string_expression will be replaced with replacement_string.</p>
<p style="text-align:justify;"><strong>Using query analyzer, name 3 ways to get an accurate count of the number of records in a table?</strong><br />
SELECT *<br />
FROM table1<br />
SELECT COUNT(*)<br />
FROM table1<br />
SELECT rows<br />
FROM sysindexes<br />
WHERE id = OBJECT_ID(table1)<br />
AND indid &lt; 2<br />
<strong>How to rebuild Master Database?</strong><br />
Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program FilesMicrosoft SQL Server80ToolsBinn directory.<br />
In the Rebuild Master dialog box, click Browse.<br />
In the Browse for Folder dialog box, select the Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK.<br />
Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases.<br />
Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK.<br />
In the Rebuild Master dialog box, click Rebuild to start the process.<br />
The Rebuild Master utility reinstalls the master database.<br />
To continue, you may need to stop a server that is running.<br />
Source: http://msdn2.microsoft.com/en-us/library/aa197950(SQL.80).aspx</p>
<p style="text-align:justify;"><strong>What is the basic functions for master, msdb, model, tempdb databases?</strong><br />
The <strong><em>Master</em></strong> database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.<br />
The <strong><em>msdb </em></strong>database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.<br />
The <strong><em>tempdb</em></strong> holds temporary objects such as global and local temporary tables and stored procedures.<br />
The <strong><em>model</em></strong> is essentially a template database used in the creation of any new user database created in the instance.</p>
<p style="text-align:justify;"><strong>What are primary keys and foreign keys?</strong><strong> </strong><br />
<strong><em>Primary keys</em></strong> are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key.<br />
<strong><em>Foreign keys</em></strong> are both a method of ensuring data integrity and a manifestation of the relationship between tables.</p>
<p style="text-align:justify;"><strong>What is data integrity? Explain constraints?</strong><br />
Data integrity is an important feature in SQL Server. When used properly, it ensures that data is accurate, correct, and valid. It also acts as a trap for otherwise undetectable bugs within applications.</p>
<p style="text-align:justify;">A <strong>PRIMARY KEY</strong> constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.</p>
<p style="text-align:justify;">A <strong>UNIQUE</strong> constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.</p>
<p style="text-align:justify;">A <strong>FOREIGN KEY</strong> constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.</p>
<p style="text-align:justify;">A <strong>CHECK</strong> constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.</p>
<p style="text-align:justify;">A <strong>NOT NULL</strong> constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.</p>
<p style="text-align:justify;"><strong>What are the properties of the Relational tables?</strong><br />
Relational tables have six properties:</p>
<ul style="text-align:justify;" type="disc">
<li>Values are atomic.</li>
<li>Column values are of the same      kind.</li>
<li>Each row is unique.</li>
<li>The sequence of columns is      insignificant.</li>
<li>The sequence of rows is      insignificant.</li>
<li>Each column must have a unique      name.</li>
</ul>
<p style="text-align:justify;"><strong>What is De-normalization?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>How to get @@error and @@rowcount at the same time?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset.<br />
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</p>
<p style="text-align:justify;"><strong>What is Identity?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>What is a Scheduled Jobs or What is a Scheduled Tasks?</strong><strong> </strong><br />
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.</p>
<p style="text-align:justify;"><strong>What is a table called, if it does not have neither Cluster nor Non-cluster Index? What is it used for?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>Unindexed table or <strong><em>Heap</em></strong>. Microsoft Press Books and Book On Line (BOL) refers it as Heap.<br />
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.<br />
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.</p>
<p style="text-align:justify;"><strong>What is BCP? When does it used?</strong><strong> </strong><br />
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.</p>
<p style="text-align:justify;"><strong>How do you load large data to the SQL server database?</strong></p>
<p style="text-align:justify;"><strong><br />
</strong>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.</p>
<p style="text-align:justify;"><strong>Can we rewrite subqueries into simple select statements or with joins? </strong><br />
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.</p>
<p style="text-align:justify;"><strong>Can SQL Servers linked to other servers like Oracle?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>How to know which index a table is using?</strong><strong> </strong><br />
SELECT table_name,index_name FROM user_constraints</p>
<p style="text-align:justify;"><strong>How to copy the tables, schema and views from one SQL server to another?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>What is Self Join?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>What is Cross Join?</strong><br />
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.</p>
<p style="text-align:justify;"><strong>Which virtual table does a trigger use?</strong><br />
Inserted and Deleted.</p>
<p style="text-align:justify;"><strong>List few advantages of Stored Procedure.</strong></p>
<p style="text-align:justify;">Stored procedure can reduced network traffic and latency, boosting application performance.</p>
<p style="text-align:justify;">Stored procedure execution plans can be reused, staying cached in SQL Server&#8217;s memory, reducing server overhead.</p>
<p style="text-align:justify;">Stored procedures help promote code reuse.</p>
<p style="text-align:justify;">Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.</p>
<p style="text-align:justify;">Stored procedures provide better security to your data.</p>
<p style="text-align:justify;"><strong>What is DataWarehousing?</strong></p>
<p style="text-align:justify;"><strong>Subject-oriented</strong>, 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;</p>
<p style="text-align:justify;"><strong>Time-variant</strong>, meaning that the changes to the data in the database are tracked and recorded so that reports can be produced showing changes over time;</p>
<p style="text-align:justify;"><strong>Non-volatile</strong>, 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;</p>
<p style="text-align:justify;"><strong>Integrated</strong>, meaning that the database contains data from most or all of an organization&#8217;s operational applications, and that this data is made consistent.</p>
<p style="text-align:justify;"><strong>What is OLTP(OnLine Transaction Processing)?</strong><br />
In OLTP &#8211; 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.</p>
<p style="text-align:justify;"><strong>How do SQL server 2000 and XML linked? Can XML be used to access data?</strong><br />
<strong><em>FOR XML (ROW, AUTO, EXPLICIT)</em></strong><br />
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.</p>
<p style="text-align:justify;"><strong><em>OPENXML</em></strong><br />
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.</p>
<p style="text-align:justify;"><strong>What is an execution plan? When would you use it? How would you view the execution plan?</strong><br />
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 &#8220;Show Execution Plan&#8221; (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.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=159&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/07/introduction-to-datawarehouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>
	</item>
		<item>
		<title>Microsoft BI Stack</title>
		<link>http://ramkarthick.wordpress.com/2009/05/07/microsoft-bi-stack/</link>
		<comments>http://ramkarthick.wordpress.com/2009/05/07/microsoft-bi-stack/#comments</comments>
		<pubDate>Thu, 07 May 2009 09:00:14 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[Business Intelligence]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/?p=134</guid>
		<description><![CDATA[Microsoft Business Intelligence Microsoft Business Intelligence is a complete and integrated offering that supports the entire organization. It is a full-featured suite of server, client, and developer products that thoroughly integrates with Microsoft Office. This thereby provides easy to use information directly where individuals work, collaborate, and make decisions. With SQL Server 2005 and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=134&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="text-align:center;"><span style="color:#800000;"><span style="color:#000000;">Microsoft Business Intelligence </span><br />
</span></h2>
<p style="text-align:justify;">Microsoft Business Intelligence is a complete and integrated offering that supports the entire organization. It is a full-featured suite of server, client, and developer products that thoroughly integrates with Microsoft Office. This thereby provides easy to use information directly where individuals work, collaborate, and make decisions.</p>
<p style="text-align:justify;">With SQL Server 2005 and the release of the 2007 Microsoft Office system, along with the capabilities found in PerformancePoint Server 2007, we cover the spectrum of performance management applications, end user tools, and the BI platform. This provides a complete BI stack. Thus we are not dependent upon BI partners.</p>
<p style="text-align:justify;">However, we provide open standards so that through partnering, we are also able to offer a wider selection of premiere solutions, thus making us a leader in the BI space. Other vendors such as IBM must partner with ISVs such as Hyperion to deliver a solution that is not equivalent to Microsoft&#8217;s offering. Overall, our offering is designed to support a leading solution and the lowest total cost of ownership.</p>
<p style="text-align:justify;"><img class="aligncenter size-full wp-image-74" title="hamburgerslide2" src="http://ramkarthick.files.wordpress.com/2009/04/hamburgerslide2.jpg?w=500" alt="hamburgerslide2"   /></p>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Analytics</span></strong>:</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Microsoft has a great story on Analytics with SQL Server Analysis services. Microsoft SQL Server 2005 Analysis Services (SSAS) delivers online analytical processing (OLAP) and data mining functionality for business intelligence applications. Analysis Services supports OLAP by letting you design, create, and manage multidimensional structures that contain data aggregated from other data sources, such as relational databases. For data mining applications, Analysis Services lets you design, create, and visualize data mining models that are constructed from other data sources by using a wide variety of industry-standard data mining algorithms.</li>
<li> Analysis Services provides a user-friendly model where you can provide understandable business names, specify relationships between fields (Product Category &#8211; Product Subcategory &#8211; Product) so that it is possible for business users to design their own reports without help from IT.</li>
<li> Analysis Services offers tools for personalizing individual users&#8217; reporting experience by only showing them the data that they care about and have permissions to see; in addition, Analysis Services can translate data into users&#8217; preferred languages.</li>
<li> Analysis Services allows you to consolidate data from different business systems into a single analytical model. In this scenario the data in SAP and other repository but for analysis that you would like to see in the same report. With an Analysis Services model, you can do just that without needing to change the source system at all.</li>
</ul>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Leveraging Office Client (Excel 2007)</span></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Excel 2007 provides great Analysis features and integrates with SSAS. With Pivot tables and visualization feature set, Excel 2007 is a great tool for Analysis.</li>
<li> Key Performance Indicators, calculations, conditional formatting, and actions are just a few examples of business logic that you can define once in Analysis Services and then expose automatically in Excel PivotTables. Part of the beauty of this is that all users see the same thing in their PivotTables because the formatting, for example, is calculated in one place &#8211; on the server.</li>
<li> When analyzing data in Analysis Services, all the business logic is centrally managed in one analytical model so that every user will see the same numbers, calculated using the same business logic. Any changes made to the model will immediately be available to all Excel PivotTable users when they update their report.</li>
</ul>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Performance / Dashboard:</span></strong></p>
<p style="text-align:justify;">Business score card manager or BSM along with Office 2007, MOSS 2007, SSAS, SSIS and SSRS provides a complete, robust end to end BI development environment on Microsoft stack.</p>
<p style="text-align:justify;"><strong><em>Deep Insight and Good Context</em></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Scorecards, reports and charts can be rapidly assembled and connected on web pages</li>
<li> Provides immediate access to analysis functionality for drilldown, filtering, sorting, and ranking</li>
<li> Insight in transactional data by drilling down through KPIs</li>
<li> Web Parts connections drive all-on-one-page interaction; Report View filters work together with Scorecard filters</li>
</ul>
<p style="text-align:justify;"><strong><em>Collaborative Business Management and Action</em></strong></p>
<ul style="text-align:justify;">
<li> BSM works with MOSS 2007 for enhanced team collaboration</li>
<li> Annotations for contextual communication</li>
<li> Integration with MS Collaboration platform.</li>
<li> Personalized scorecards and views of relevant reports, tasks, project plans and notifications</li>
<li> Data-driven alerts available on Scorecard and KPIs</li>
<li> Distribution is made easy with export capabilities to Excel, PDF, HTML and TIFF formats</li>
</ul>
<p style="text-align:justify;"><strong><em>End User Empowerment</em></strong></p>
<ul style="text-align:justify;">
<li> Provides business analysts the ability to build, manage and consume KPI&#8217;s and scorecards</li>
<li>Enables building comprehensive views that include charting, reports and pivot for detailed analysis</li>
<li>Provides end users the ability to add / change personal scorecard views.</li>
</ul>
<p style="text-align:justify;"><strong><em>Extensible Solution</em></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Ability to extend BSM with advanced analysis solutions</li>
<li> Easy integration with LOB Applications</li>
<li> Partners can extend BSM using its Web Services APIs and SharePoint platform</li>
<li> BPM ISVs can extend Microsoft Office Business Scorecard Manager 2005 using it&#8217;s SharePoint platform and web services APIs to provide an end to end BPM offering</li>
</ul>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Reporting</span></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> SQL Server Reporting Services is natively integrated with .NET report services and is part of whole Microsoft BI solutions. It is designed to provide one of the most comprehensive BI and reporting solutions on the market today.</li>
<li> Reporting Services in SQL Server 2005 provides enterprise reporting capabilities and addresses a new audience-business users who want to interact with data in an ad hoc fashion as well as create their own reports from scratch and to share them with others.</li>
<li> SQL Server 20005 Reporting Services has many improvements in the areas of report design, processing, and interactivity. There are also improvements to performance and scalability.</li>
<li> SSRS provides enhanced integration with other components within SQL Server 2005 including SQL Server Integration Services (SSIS), SQL Server Analysis Services (SSAS), and SQL Server Management Studio. Reporting Services also has tighter integration with Microsoft SharePoint Products and Technologies, enabling reports to easily participate in corporate portal scenarios.</li>
<li> Reporting Services provides unparalleled reporting integration into the Visual Studio development environment. In addition, freely redistributable Microsoft Windows and ASP.NET controls make it easy to embed reporting in both server-based and client-based applications.</li>
<li> SQL Server 2005 Reporting Services includes Report Builder, a new <em>ad hoc</em> reporting tool that enables business users to create their own reports and explore corporate data. Report Builder incorporates a user-friendly business query model that enables users to build reports without deep technical understanding of the underlying data sources.</li>
</ul>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Integration</span></strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> SQL 2005 is an integrated platform to create Data Warehousing applications, data mining tools are consolidated into two working environments in SQL 2005, Business Intelligence Development Studio and SQL Server Management Studio.</li>
</ul>
<ul class="unIndentedList" style="text-align:justify;">
<li> SQL Server Integration Services (SSIS) goes beyond being an ETL tool not only in terms of enabling nontraditional scenarios, but also in being a true platform for data integration. SSIS is part of the SQL Server Business Intelligence (BI) platform which enables the development of end-to-end BI applications.</li>
</ul>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Microsoft Office SharePoint Server 2007</span></strong></p>
<p style="text-align:justify;">SharePoint server deliver centralized access to information. SharePoint portal server makes it easy to create live, interactive business intelligence (BI) portals that assemble and display business-critical information from disparate sources, using integrated BI capabilities such as dashboards, Web Parts, scorecards, key performance indicators (KPIs), and business data connectivity technologies. Centralized Report Center sites give users a single place for locating the latest reports, spreadsheets, or KPIs.</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Excel Services and Reporting Services in the portal</li>
<li> Report Center: out-of-the-box BI portal experience</li>
<li> Dashboards, KPIs, and Report Libraries</li>
<li> Integrated with Portal, Collaboration, Enterprise Content Management and Workflow functionality</li>
</ul>
<p style="text-align:justify;">Excel Services runs spreadsheets and performs calculations on a Web server, delivering results to users through a browser and to other applications through a Web services API.</p>
<p style="text-align:justify;"><strong><span style="text-decoration:underline;">Performance Point Server:</span></strong></p>
<p style="text-align:justify;">Microsoft Office PerformancePoint Server 2007 is a complete Performance Management (PM) application providing Score carding, Analytics and Planning for enterprise and mid-market customers.  Office PerformancePoint Server 2007 enables businesses to improve their performance by providing all employees with the ability to measure manage and align their activities to company strategy using the familiar and easy-to-use Microsoft Office environment they already know and use every day.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=134&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2009/05/07/microsoft-bi-stack/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://ramkarthick.files.wordpress.com/2009/04/hamburgerslide2.jpg" medium="image">
			<media:title type="html">hamburgerslide2</media:title>
		</media:content>
	</item>
		<item>
		<title>About ME !!!!!</title>
		<link>http://ramkarthick.wordpress.com/2007/09/01/about-me/</link>
		<comments>http://ramkarthick.wordpress.com/2007/09/01/about-me/#comments</comments>
		<pubDate>Sat, 01 Sep 2007 06:33:00 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/2007/09/01/about-me/</guid>
		<description><![CDATA[I am this little pest who lives in this insane world and walk along the sands of the seashore, wishing that the sea breeze will make me sane but they too had made me insane &#8230;.and i ramble my endless thoughts of insaneness and saneness in this sane less insane world&#8230;.i follow my own rules [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=21&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://1.bp.blogspot.com/_lFULfgj9wV4/RtkIEUeE-qI/AAAAAAAAAGY/icxkENC5pIo/s1600-h/bench.gif"><img style="display:block;text-align:center;margin:0 auto 10px;" alt="" src="http://1.bp.blogspot.com/_lFULfgj9wV4/RtkIEUeE-qI/AAAAAAAAAGY/icxkENC5pIo/s400/bench.gif" border="0" /></a>
<div align="justify">                      <span style="color:rgb(51,51,51);"> I am this little pest who lives in this insane world and walk along the sands of the seashore, wishing that the sea breeze will make me sane but they too had made me insane &#8230;.and i ramble my endless thoughts of insaneness and saneness in this sane less insane world&#8230;.i follow my own rules and principles&#8230;..i live life my way&#8230;.i ponder endlessly of things which are not insane in this insane world&#8230;.because those things shouldn&#8217;t happen..they are technically not allowed in this insane world&#8230; (in short..i am insane always and a lil bit sane at times!!) </span></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ramkarthick.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ramkarthick.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=21&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2007/09/01/about-me/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://1.bp.blogspot.com/_lFULfgj9wV4/RtkIEUeE-qI/AAAAAAAAAGY/icxkENC5pIo/s400/bench.gif" medium="image" />
	</item>
		<item>
		<title>My First Step.. Where I Started my Career</title>
		<link>http://ramkarthick.wordpress.com/2007/08/31/about-my-company/</link>
		<comments>http://ramkarthick.wordpress.com/2007/08/31/about-my-company/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 05:52:00 +0000</pubDate>
		<dc:creator>Ramkarthick</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://ramkarthick.wordpress.com/2007/08/31/about-my-company/</guid>
		<description><![CDATA[Prediktiva is a business analytics consulting and systems integration firm with a mission to enable intelligent, data-driven decision making at every level of the 21st century organization. We use our skills, experience, tools and methodology to deliver analytics infrastructure and application solutions that bridges the gap that today’s customer-centric organizations face, the gap between wealth [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=20&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div><a href="http://2.bp.blogspot.com/_lFULfgj9wV4/RtetAEeE-oI/AAAAAAAAAGI/oUCdCmfb8YI/s1600-h/img-brain.gif"><img style="display:block;cursor:pointer;text-align:center;margin:0 auto 10px;" src="http://2.bp.blogspot.com/_lFULfgj9wV4/RtetAEeE-oI/AAAAAAAAAGI/oUCdCmfb8YI/s400/img-brain.gif" border="0" alt="" /></a><span style="color:#333333;"><br />
</span><span style="color:#333333;">Prediktiva is a business analytics consulting and systems integration firm with a mission to enable intelligent, data-driven decision making at every level of the 21st century organization. We use our skills, experience, tools and methodology to deliver analytics infrastructure and application solutions that bridges the gap that today’s customer-centric organizations face, the gap between wealth of data on one side and profitable decision making on the other. </span></div>
<div><span style="color:#333333;"> Putting together a Business Analytics solution is like solving a jigsaw puzzle that involves Integration of data from various internal and external sources Development of a data warehouse that evolves with the business Mining the data for hidden insights Visualization and presentation of the insights in various forms at various levels in the organization .</span></div>
<div><span style="color:#333333;"> It is a complex undertaking with a promise of a huge and sustained reward in the end. Prediktiva helps put the jigsaw of Business Analytics software applications together!</span></div>
<div><span style="color:#333333;">We are happy to announce that we the  part of <strong>G4Analytics</strong> US . </span></div>
<div><span style="color:#333333;">see the link for further Information </span><strong>http://www.g4analytics.com/?p=533</strong></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ramkarthick.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ramkarthick.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ramkarthick.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ramkarthick.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ramkarthick.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ramkarthick.wordpress.com&amp;blog=7306934&amp;post=20&amp;subd=ramkarthick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ramkarthick.wordpress.com/2007/08/31/about-my-company/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/78eff88351b9f4d9df459efd0cd542ca?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ramkarthick</media:title>
		</media:content>

		<media:content url="http://2.bp.blogspot.com/_lFULfgj9wV4/RtetAEeE-oI/AAAAAAAAAGI/oUCdCmfb8YI/s400/img-brain.gif" medium="image" />
	</item>
	</channel>
</rss>
