Skip to main content

SQL Questions and Answers - Part 2

Continue from previous part.

What is a constraint?
Constraints let you define the way the Database Engine automatically enforces the integrity of a database. Constraints define rules regarding the values allowed in columns and are the standard mechanism for enforcing integrity. SQL Server supports the following classes of constraints:
NOT NULL specifies that the column does not accept NULL values.
CHECK constraints enforce domain integrity by limiting the values that can be put in a column.
UNIQUE constraints enforce the uniqueness of the values in a set of columns.
PRIMARY KEY constraints identify the column or set of columns that have values that uniquely identify a row in a table.
FOREIGN KEY constraints identify and enforce the relationships between tables.
Read more at http://msdn.microsoft.com/

What is a unique constraint?
A Unique constraint uniquely identified each record in a table. This provides uniqueness for the column or set of columns. Use a Unique constraint when you want to enforce the uniqueness of a column, or combination of columns, that is not the primary key. Unique constraint creates a non-clustered index on the column. Unique Key allows only one NULL Value.

What is a Foreign Key (FK)?
A foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data in two tables. You can create a foreign key by defining a FOREIGN KEY constraint when you create or modify a table.
Read more at http://msdn.microsoft.com/

What is the difference between Primary Key (PK) and Unique Key (UK)?
A Primary Key (PK) can not have a Null value. A Unique Key can have one Null value.
Primary Key creates a clustered index on the column. Unique Key creates a non-clustered index on the column.
Each table may have only one PK but many unique constraints.

What is a join?
An SQL join clause combines records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each. ANSI standard SQL specifies four types of JOIN: INNER, OUTER, LEFT, and RIGHT. As a special case, a table (base table, view, or joined table) can JOIN to itself in a self-join.

What are the types of join?
Inner Join: Inner join returns only the rows that have a match in both joined tables.
Right Outer Join: Right join returns all the rows from the right hand side table even though there are no matches in the left hand side table.
Left Outer Join: Left join returns all the rows from left hand side table even though there are no matches in the right hand side table.
Full Outer Join: Full join returns all rows in all joined tables are included, whether they are matched or not. Cross Join: Cross join return all rows from the left table. Each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
Read more at http://msdn.microsoft.com/


Related posts:
SQL Questions and Answers – Part 3
SQL Questions and Answers – Part 2
SQL Questions and Answers – Part 1

Comments

Popular posts from this blog

Visual Studio 2010 Keyboard Shortcuts

These keyboard shortcuts are helpful. Some of them are not document in Visual Studio 2010 Express, for example: <Ctrl> F5 to run the application without debug <Ctrl> Period or <Ctrl> Space for code completion. <Ctr> <Shift> <B> to build the solution For more download the Visual Studio 2010 Keybinding Posters from Microsoft. Credit:  Visual Studio 2010 Keyboard Shortcuts - ScottGu's Blog DevCurry: 30 Favorite Visual Studio Keyboard Shortcuts

Install Android Development Tools on Ubuntu 12.10 (Quantal Quetzal)

First thing first. Make sure Java Development Kit (JDK) install. Go to Terminal and type 'Java -version' to check. You should see the following: java version "1.7.0_07" OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-1ubuntu1) OpenJDK Server VM (build 23.2-b09, mixed mode) If Java Development Kit is not installed, you can install it from Ubuntu Software Center. Click on Ubuntu Software Center icon from left side bar and search for Java. Here, I selected 'OpenJava JDK 7 runtime' Go to http://www.eclipse.org/downloads/ to download Eclipse Classic 4.2.1 (Juno) Go to your downloads folder and extract it. Move 'eclipse' folder to your home directory. Launch Eclipse 4.2.1 (Juno) from 'eclipse' folder. Install Android Developer Tools (ADT) plugin for Eclipse. Click on Help -> Install New Software and add the URL 'https://dl-ssl.google.com/android/eclipse/' on the input text box next to 'Work with' and click the 'Add

ASP.NET Questions and Answers - Part 2

How can we prevent browser from caching an ASPX page?  Use the SetNoStore method of the HttpCachePolicy class to direct the client not to store the responses in its history. See http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.setnostore.aspx In which event are the controls fully loaded? On Load event. ( http://msdn.microsoft.com/en-us/library/system.web.ui.page(v=vs.100).aspx )  The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page. Use the OnLoad event method to set properties in controls and to establish database connections. (http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx ) How we can force all the validation controls to run? Using Page.Validate() method to instructs any validation controls included on the page to validate their assigned information. Read more at h