SQLQueries First Editon PDF
SQLQueries First Editon PDF
This free book is provided by courtesy of C# Corner and Mindcracker Network and its
authors. Feel free to share this book with your friends and co-workers. Please do not
reproduce, republish, edit or copy this book.
Sam Hobbs
Editor, C# Corner
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Table of Content
1. Environment Setup
2. SQL Queries
2.1 Get all columns and all rows from table
2.2 Get desired columns and all rows from table
2.3 Get all columns from table where column name is equal to xxx
2.4 Get all columns from table where column name between xxx and xxx
2.5 Get all rows from table where column name is aaa,bbb,xxx
2.6 Get all rows from table where column name starts with 'x' letter
2.7 Get all rows from table where column name ends with 'x' letter
2.8 Get all rows from table where column name starts with 'x/z' letter
2.9 Get all rows from table where column name does not start with 'x/z' letter
2.10 Get single column with a combination of two columns and all rows from table
2.11 Get all rows from table where column name is not containing null values
2.12 Get all rows from table in descending order of column name
2.13 Get all rows from table in ascending order of column name
2.14 Get unique rows from table based on column name
2.15 Get top 5 rows from table name
2.16 Get maximum column value from table by column name
2.17 Get maximum column value from table by column name using COMPUTE
2.18 Get even row from table 'Product'
2.19 Get odd row from table 'Product'
2.20 Count number of records in a 'Product' table
2.21 List all the categories with products (Inner Join)
2.22 List all rows from category, with products (Left Join)
2.23 List all the rows from products (Right Join)
2.24 List all the rows from the category table and product table (Full Join)
2.25 Get average value of price from product table
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.26 Get number of products from product table
2.27 Get Maximum price of product from product table
2.28 Get minimum price of product from product table
2.29 Get total number of qty of products from product table
2.30 Get all product name is in upper case from product table
2.31 Get all product name is in lower case from product table
2.32 List all columns of all tables in a database
2.33 List all tables which have column name like 'CategoryId'
2.34 List number of records in each table in a database
2.35 List all tables in a database
2.36 List all procedures from a database
2.37 List all tables in all databases
2.38 List all Stored Procedures in All Databases
2.39 List sizes of all tables in a database
2.40 List sizes of all database files
2.41 Generate xsd of a table without data
2.42 Generate xsd of a table with data
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
1. Environment Setup
Follow the following steps in your sql server before you execute all the queries available in this
book.
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Insert database name as ‘ProductDb’ and press ok button.
Add CategoryId of type bigint and CategoryName of type varchar with the size of 50.
Right click on the field ‘CategoryId’ and select ‘Set Primary Key’.
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Now set identity specification in column properties of ‘CategoryId’ column.
Now you can see the table ‘Category’ under the ‘Tables’ Folder.
Now follow the above steps once again and create one more table ‘Product’.
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
After creating product table set foreign key relation between ‘CategoryId’ of Category table and
‘CategoryId’ of Product table.
Now insert some data in both the tables by executing following query:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Now insert few records into ‘Product’ table:
2. Sql Queries
2.1: Get all columns and all rows from ‘Product’ table
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
ProductId CategoryId ProductName Qty Price Description
1 1 Pen 10 15 Good pen for exam
2 1 Pencil 100 5 Good pencil for drawing
3 1 Notebook 50 25 Notebook for primary students
4 1 Fullscape 200 15 Fullscape for higer secondary students
5 1 Eraser 1000 1.5 Eraser for KG Students
6 2 Mouse 20 200 USB 2.0 Mouse
7 2 Keyboard 20 250 USB 3.0 Keyboard
8 2 USB Stick 1000 450 4 GB Pendrives
Messages:
(8 row(s) affected)
Description:
It feteches all the records available in the product table. ‘*’ is used in conjuction with query to fetch all
the columns value.
Note: ‘*’ can be replaced with column names if only speicific columns need to be shown.
2.2: Get Column with their respective values from the table.
Query:
Result:
(8 row(s) affected)
Description:
It fetches columns value from product table and columns are seperated by comma operator. Here you
are not using *, as you want to fetch only specific columns.
2.3: Get all columns from ‘Product’ table with where clause.
‘ProductId’ is equal to 2
Query:
Result:
ProductNam
ProductId CategoryId e Qty Price Description
Good pencil for
2 1 Pencil 100 5 drawing
Messages:
(1 row(s) affected)
Description:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.4: Get all columns from ‘Product’ table using Between Operator.
Query:
Result:
Messages:
(5 row(s) affected)
Description:
It fetches records from the product table where productid ranges between 4 and 8.
For this purpose BETWEEN operator is used in conjuction with WHERE clause.
2.5: Get all rows from ‘Product’ table where ProductName is Mouse,Keyboard,USB Stick
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
(3 row(s) affected)
Description:
It feteches the records from the product table where productname could be any of the names
specified in ‘in clause’ For e.g.
It fetches those rows from the table where ProductName could be either Mouse or Keyboard or
USB Stick.
Hence, IN clause is used to specify more than one choices/options in conjuction with WHERE
clause.
2.6: Get all rows from ‘Product’ table where the name starts with ‘K’ letter.
Query:
Result:
Messages:
(1 row(s) affected)
Description:
It fetches records from the product table where ProductName starts with K.
2.7: Get all rows from ‘Product’ table where the name ends with ‘K’ letter.
Query:
Result:
ProductNa
ProductId CategoryId me Qty Price Description
Notebook for primary
3 1 Notebook 50 25 students
8 2 USB Stick 1000 450 4 GB Pendrives
Messages:
(2 row(s) affected)
Description:
2.8: Get all rows from ‘Product’ table where the name starts with ‘E/F’ letter.
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
ProductNam
ProductId CategoryId e Qty Price Description
Fullscape for higer secondary
4 1 Fullscape 200 15 students
5 1 Eraser 1000 1.5 Eraser for KG Students
Messages:
(2 row(s) affected)
Description:
It fetches records from the product table where ProductName start with either ‘E’ or ‘F’.
2.9: Get all rows from ‘Product’ table where the name not starts with ‘E/F’ letter.
Query:
Result:
Messages:
(6 row(s) affected)
Description:
It fetches records from the product table where ProductName doesn’t start with either ‘E’ or ‘F’.
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.10: Get single column with a combination of Product and Qty added together with a space from
Product’ table
Query:
Result:
ProductWithQty
Pen 10
Pencil 100
Notebook 50
Fullscape 200
Eraser 1000
Mouse 20
Keyboard 20
USB Stick 1000
Messages:
(8 row(s) affected)
Description:
In this query, Additonal data i.e SPACE(1) is added to add space between ProductName and
ProductQty. So additional data can be added within the select query using ‘+’ operator.
2.11: Get all rows from ‘Product’ table where ProductName column is not containing null values
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
ProductId CategoryId ProductName Qty Price Description
1 1 Pen 10 15 Good pen for exam
2 1 Pencil 100 5 Good pencil for drawing
3 1 Notebook 50 25 Notebook for primary students
4 1 Fullscape 200 15 Fullscape for higer secondary students
5 1 Eraser 1000 1.5 Eraser for KG Students
6 2 Mouse 20 200 USB 2.0 Mouse
7 2 Keyboard 20 250 USB 3.0 Keyboard
8 2 USB Stick 1000 450 4 GB Pendrives
Messages:
(7 row(s) affected)
Description:
It fetches records from the Product database where Description is not null.
In some cases data could remain NULL, so in order to find out only those records which are not
null ‘IS NOT NULL’ clause is used in conjunction with WHERE clause/condition.
2.12: Get all rows from ‘Product’ table in descending order of ProductId
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
(8 row(s) affected)
Description:
2.13: Get all rows from ‘Product’ table in ascending order of ProductId
Query:
Result:
Messages:
(8 row(s) affected)
Description:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.14: Get Unique row from ‘Product’ table based on CategoryId
Query:
Result:
CategoryId
1
2
Messages:
(2 row(s) affected)
Description:
Query:
Result:
Messages:
(5 row(s) affected)
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Description:
Hence, TOP n statement is used to fetch top n rows from the table.
Query:
Result:
(No column
name)
8
Messages:
(1 row(s) affected)
Description:
In this case ProductId is passed in MAX() function, so returns the row having maximum value of
ProductId.
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
ProductId CategoryId ProductName Qty Price Description
1 1 Pen 10 15 Good pen for exam
2 1 Pencil 100 5 Good pencil for drawing
3 1 Notebook 50 25 Notebook for primary students
Fullscape for higer secondary
4 1 Fullscape 200 15 students
5 1 Eraser 1000 1.5 Eraser for KG Students
6 2 Mouse 20 200 USB 2.0 Mouse
7 2 Keyboard 20 250 USB 3.0 Keyboard
8 2 USB Stick 1000 450 4 GB Pendrives
max
1000
Messages:
(9 row(s) affected)
Description:
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
(4 row(s) affected)
Description:
Query:
Result:
Messages:
(4 row(s) affected)
Description:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.20: Count number of records in a 'Product' table
Query:
Result:
RecordCount
8
Messages:
(1 row(s) affected)
Description:
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
CategoryI CategoryNam ProductI CategoryI ProductNam
d e d d e Qty Price Description
Good pen for
1 Stationery 1 1 Pen 10 15 exam
Good pencil for
1 Stationery 2 1 Pencil 100 5 drawing
Notebook for
primary
1 Stationery 3 1 Notebook 50 25 students
Fullscape for
higer secondary
1 Stationery 4 1 Fullscape 200 15 students
100 Eraser for KG
1 Stationery 5 1 Eraser 0 1.5 Students
2 Computer 6 2 Mouse 20 200 USB 2.0 Mouse
USB 3.0
2 Computer 7 2 Keyboard 20 250 Keyboard
100
2 Computer 8 2 USB Stick 0 450 4 GB Pendrives
Messages:
(8 row(s) affected)
Description:
The INNER JOIN keyword returns rows when there is at least one match in both tables. If there are rows
in "Product" that do not have matches in "Category", those rows will NOT be listed.
Inner join creates a new result table by combining column values of two tables (A and B) based upon the
join-predicate. The query compares each row of A with each row of B to find all pairs of rows which
satisfy the join-clause.
The "explicit join notation" uses the JOIN keyword to specify the table to join, and the ON keyword to
specify the predicates for the join, as in the following example:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
SELECT * FROM Category
INNER JOIN Product
ON Category.CategoryId = Product.CategoryId
The following example is equivalent to the previous one, but this time using implicit join notation:
2.22: List all rows from category, even if there are no matches in the product table (Left Join)
Query:
Result:
Messages:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
(10 row(s) affected)
Description:
The LEFT JOIN keyword returns all the rows from the left table (Category), even if there are no matches in
the right table (Product).
This means that if the ON clause matches 0 (zero) records in Table B (for a given record in Table A), the
join will still return a row in the result (for that record)—but with NULL in each column from Table B.
2.23: List all the rows from product, even if there are no matches in the category table (Right Join)
Query:
Result:
Messages:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Description:
The RIGHT JOIN keyword returns all the rows from the right table (Product), even if there are no matches
in the left table (Category).
2.24: List all the rows from the category table and all the rows from the product table (Full Join)
Query:
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
(12 row(s) affected)
Description:
The FULL JOIN keyword returns all the rows from the left table (Category), and all the rows from the right
table (Product). If there are rows in "Category" that do not have matches in "Product", or if there are
rows in "Product" that do not have matches in "Category", those rows will be listed as well.
Query:
Result:
PriceAverage
296.15
Messages:
(1 row(s) affected)
Description:
Query:
Result:
NoOfProducts
10
Messages:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
(1 row(s) affected)
Description:
Query:
Result:
MaximumPrice
1500
Messages:
(1 row(s) affected)
Description:
The MAX() function returns the maximum value of the selected column.
Query:
Result:
MinimumPrice
1.5
Messages:
(1 row(s) affected)
Description:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
The MIN() function returns the smallest value of the selected column.
Query:
Result:
TotalProducts
2420
Messages:
(1 row(s) affected)
Description:
2.30: Get all product name is in upper case from product table
Query:
Result:
PRODUCTS
PEN
PENCIL
NOTEBOOK
FULLSCAPE
ERASER
MOUSE
KEYBOARD
USB STICK
TABLE
CHAIR
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
Description:
2.31: Get all product name is in lower case from product table
Query:
Result:
Products
pen
pencil
notebook
fullscape
eraser
mouse
keyboard
usb stick
table
chair
Messages:
Description:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.32: List all columns of all tables in a database
Query:
Result:
TableName ColumnName
Category CategoryId
Category CategoryName
Product ProductId
Product CategoryId
Product ProductName
Product Qty
Product Price
Product Description
Messages:
(8 row(s) affected)
Description:
It pulls out all the columns of all the tables of the active/current working database. In order to
achieve this sys.columns table is used, as it is a system table (prefixed with sys).
* You can check rest of the fields/columns available in sys.columns table using the following
query
These queries could be useful for DBA’s or programmers to create scripts etc.
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
2.33: List all tables which have column name like 'CategoryId'
Query:
SELECT
sys.tables.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
sys.columns.name AS column_name
FROM sys.tables
INNER JOIN sys.columns
ON sys.tables.OBJECT_ID = sys.columns.OBJECT_ID
WHERE sys.columns.name LIKE '%CategoryId%'
ORDER BY schema_name, table_name
Result:
Messages:
(2 row(s) affected)
Description:
It pulls out records from sys.tables having column ‘CategoryId’ available in any of the tables for the
current working database.
Like sys.columns, sys.tables is also a system table and provide meaningful information about the
tables.
Query:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
DECLARE @DSql VARCHAR(MAX)
SELECT @DSql =
COALESCE(@DSql + CHAR(13) + ' UNION ALL ' + CHAR(13), '') +
'SELECT ' + QUOTENAME(TABLE_NAME,'''') + ' as [Table Name], COUNT(*) AS [Records Count]
FROM ' + QUOTENAME(Table_schema) + '.' + QUOTENAME(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_NAME
EXEC( @DSql)
Result:
Product 8
Messages:
(2 row(s) affected)
Description:
It pulls out total number of records available for each table in the current working database.
Query:
Result:
Table
Table Schema Name
Dbo Category
Dbo Product
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
Messages:
(2 row(s) affected)
Description:
It lists out all the tables created under the active working database.
Query:
Result:
Messages:
(2 row(s) affected)
Description:
Again helpful for DBA’s (Database Administrator) and programmers to keep track of number of
procedures made along with meaningful details like createddate, last modified date.
Query:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
CREATE TABLE #Temp
(
DBName sysname,
TableSchema sysname,
TableName sysname
)
DECLARE @DSql NVARCHAR(MAX)
EXECUTE(@DSql)
Result:
Messages:
(6 row(s) affected)
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
(0 row(s) affected)
.....
Description:
Query:
EXECUTE (@DSql)
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
DBName SPName create_date modify_date
master sp_MScleanupmergepublisher 2012-08-23 00:10:07.397 2012-08-23 00:10:07.440
......
Messages:
(2 row(s) affected)
(0 row(s) affected)
.....
Description:
Query:
EXECUTE (@DSql)
Result:
Messages:
(2 row(s) affected)
Description:
Query:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
DECLARE @DSql NVARCHAR(MAX)
SET @DSql = ''
SELECT @DSql = @DSql + 'USE' + QUOTENAME(name) + '
INSERT INTO #Temp
SELECT ' + QUOTENAME(name,'''') + ', Name,
Physical_Name, size/1024.0 from sys.database_files'
FROM sys.databases
EXECUTE (@DSql)
Result:
Messages:
Description:
These files have extension (.ldf) and can be found at following location
C:\Program Files\....
Query:
SET @myXsd = (SELECT TOP 0 * FROM Category FOR XML AUTO, ELEMENTS,
XMLSCHEMA('myTargetNamespace'))
SET @myXsd.modify('delete /xs:schema[1]/@targetNamespace')
SELECT @myXsd
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes"
schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd"
/>
<xsd:element name="Category">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CategoryId" type="sqltypes:bigint" />
<xsd:element name="CategoryName" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033"
sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth"
sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Messages:
(1 row(s) affected)
Description:
Query:
SELECT @XsdSchema
Result:
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes"
schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd"
/>
<xsd:element name="Category">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CategoryId" type="sqltypes:bigint" />
<xsd:element name="CategoryName" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033"
sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth"
sqltypes:sqlSortId="52">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<Category xmlns="TestXsdSchema">
<CategoryId>1</CategoryId>
<CategoryName>Stationery</CategoryName>
</Category>
<Category xmlns="TestXsdSchema">
<CategoryId>2</CategoryId>
<CategoryName>Computer</CategoryName>
</Category>
Messages:
(1 row(s) affected)
©2014 C# CORNER.
SHARE THIS DOCUMENT AS IT IS. PLEASE DO NOT REPRODUCE, REPUBLISH, CHANGE OR COPY.