Hello friends,
Recently a question asked to my friend in an interview “How to write an insert statement for a table which has only single column and that column is auto incremented?”
So here is the answer for it with sample
DECLARE @tblTest AS TABLE (id INT IDENTITY)
INSERT INTO @tblTest DEFAULT VALUES
INSERT INTO @tblTest DEFAULT VALUES
INSERT INTO @tblTest DEFAULT VALUES
INSERT INTO @tblTest DEFAULT VALUES
INSERT INTO @tblTest DEFAULT VALUES
SELECT * FROM @tblTest
But I don’t know what will be the use of this table?
Enjoy Query
Thanks & Regards
Rajat Jaiswal
this blog is basically for those people who want to help other and help themselves in web development.Main key feature of this blog is asp, asp.net ,Php and other web development lanaguage & Database
Tuesday, December 28, 2010
Monday, December 27, 2010
Generate thumbnail image in asp.net
Dear All,
Many times we require thumbnail image on the fly.
ASP.Net provides an easy way by which we can create thumbnail. I am showing basic steps by which we can create thumbnail.
Asp.net provides “System.Drawing.Image “namespace which having property “GetThumbnailImage” by which we can get Thumbnail image.
It’s a simplest way to get a thumbnail.
Below is the code written in VB.NET by which we upload an image, save image & create thumbnail and save thumbnail with thumbnail prefix.
Protected Sub Unnamed1_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
If Me.FileUpload1.FileName.Trim <> String.Empty AndAlso Me.FileUpload1.FileContent.Length > 0 Then
Dim strUploadPath As String = Server.MapPath("images")
Dim strFileName As String = Me.FileUpload1.FileName
FileUpload1.SaveAs(strUploadPath & "\" & strFileName)
Dim img1 As System.Drawing.Image = System.Drawing.Image.FromFile(strUploadPath & "\" & strFileName)
Dim thumbNail As System.Drawing.Image = img1.GetThumbnailImage(100, 100, Nothing, IntPtr.Zero)
thumbNail.Save(strUploadPath & "\thubmnail_" & strFileName)
Me.imgActual.ImageUrl = "~/images/" & strFileName
Me.imgThumb.ImageUrl = "~/images/" & "thubmnail_" & strFileName
End If
Catch ex As Exception
End Try
End Sub
Enjoy programming.
Thanks & Regards
Rajat Jaiswal
Many times we require thumbnail image on the fly.
ASP.Net provides an easy way by which we can create thumbnail. I am showing basic steps by which we can create thumbnail.
Asp.net provides “System.Drawing.Image “namespace which having property “GetThumbnailImage” by which we can get Thumbnail image.
It’s a simplest way to get a thumbnail.
Below is the code written in VB.NET by which we upload an image, save image & create thumbnail and save thumbnail with thumbnail prefix.
Protected Sub Unnamed1_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
If Me.FileUpload1.FileName.Trim <> String.Empty AndAlso Me.FileUpload1.FileContent.Length > 0 Then
Dim strUploadPath As String = Server.MapPath("images")
Dim strFileName As String = Me.FileUpload1.FileName
FileUpload1.SaveAs(strUploadPath & "\" & strFileName)
Dim img1 As System.Drawing.Image = System.Drawing.Image.FromFile(strUploadPath & "\" & strFileName)
Dim thumbNail As System.Drawing.Image = img1.GetThumbnailImage(100, 100, Nothing, IntPtr.Zero)
thumbNail.Save(strUploadPath & "\thubmnail_" & strFileName)
Me.imgActual.ImageUrl = "~/images/" & strFileName
Me.imgThumb.ImageUrl = "~/images/" & "thubmnail_" & strFileName
End If
Catch ex As Exception
End Try
End Sub
Enjoy programming.
Thanks & Regards
Rajat Jaiswal
Saturday, December 25, 2010
Project List On which i have to work
Dear Friends,
Merry Christmas!
I Hope you are enjoying the holidays.
After seeing the market trend and requirements I am interested in making following projects which will help me and other friends to understand basic project development and use latest technologies with some productive output.
In coming up sessions i am going to use this project topic and create sample with latest technologies like Silverlight, Windows phone 7, VS 2010 etc.
So here we go
1) College Management
2) School Management
3) Job Portal
4) Forums
5) Blog
6) Employee Management
7) Bug Tracker
8) Time Sheet
9) Address Book
10) Project Management
11) Survey engine
12) Stock Manager
13) Property Broker
14) Shop Management
15) Matrimonial
16) Social Networking
17) Hotel Management
18) Inventory Management
19) Accounting
20) Transport Management
21) Hospital Management
22) Ecommerce
Etc are the project list on which I will work in future to enhance my knowledge with productive work.
I will share code base and case study also in future
Hope you like it Once again wish you Merry Christmas.
Thanks
Rajat Jaiswal
Merry Christmas!
I Hope you are enjoying the holidays.
After seeing the market trend and requirements I am interested in making following projects which will help me and other friends to understand basic project development and use latest technologies with some productive output.
In coming up sessions i am going to use this project topic and create sample with latest technologies like Silverlight, Windows phone 7, VS 2010 etc.
So here we go
1) College Management
2) School Management
3) Job Portal
4) Forums
5) Blog
6) Employee Management
7) Bug Tracker
8) Time Sheet
9) Address Book
10) Project Management
11) Survey engine
12) Stock Manager
13) Property Broker
14) Shop Management
15) Matrimonial
16) Social Networking
17) Hotel Management
18) Inventory Management
19) Accounting
20) Transport Management
21) Hospital Management
22) Ecommerce
Etc are the project list on which I will work in future to enhance my knowledge with productive work.
I will share code base and case study also in future
Hope you like it Once again wish you Merry Christmas.
Thanks
Rajat Jaiswal
Friday, December 03, 2010
Best Practices in database design (SQL Server)
Hello friends,
Designing database is one of the most interesting works but on the same time it should be proper because it is base of any business application. We should follow Microsoft best practices while designing the database. Here I am with a simple database design (Address book) concept. I will try to put my best to use Microsoft best practices while designing database. I know you are thinking Address book is so much easy to design, so my answer is yes you are right you can design database easily but using Microsoft best practices it bit more important and I am trying for those best practices.
So first best practice is
1)Define proper data type :-
Most of the time we design database but we ignore proper database but it should not because when you talking for very large scale database application (VLSDB) then wrong data type will give you space problem. According to best practices choose smallest data type first (if it fit in your requirement).We understand this by an example suppose you designed a table with name “seed Data” in which column with name lngId having data type float and float consume 8 bytes and if the seed data cannot exceed more than 10 rows then we should use Tinyint data type instead of float data type because tinyint consume only 1 byte.
2)Define proper Primary & Foreign key:-
According to best practices we should make database normalized and for normalized database we should create proper Primary & Foreign keys. By creating proper primary & foreign keys we get two advantage 1) data anomalies chances reduce we get fast response as well after defining primary key (because cluster index created on primary key)
3)Define proper constraints :-
Microsoft best practices also suggest defining proper constraints for column like not null, unique key constraint on columns so that data anomalies will reduce and we get proper data.
4)Define partition :-
If your database is going to be very large then define proper partition both horizontally & vertically.
5)Normalization: - Database should be proper normalized.
In our Address Book database example we have categorized the data table in 3 categories
1)Lookup table having prefix “lku”
The lookup table is mainly for seed value or we can say this table contains all the data which just act like pre pop data. We have following tables for our Address book
lkuCountryMaster,lkuStateMaster,lkuCityMaster,lkuPhoneType,lkuAddressType,lkuPrefixMaster,lkuURLType,lkuDesignationType,lkuRelationShipType
2)Link table having prefix “lnk”
By the name it is clear that its main purpose is making relation between main data record and other data. We have used following tables lnkPhoneToPerson,lnkAddressToPerson,lnkAddressToCompany,lnkURLToPerson,lnkPersonToCompany,lnkPersonRelations,lnkPhoneToCompany
3)Main table which start with prefix “tbl”
The main table indicates by “tbl” in our Address book database we have used following tables tblPerson, tblAddresses, tblPhotos and tblCompany.
In the entire lookup table we have preferred tiny int & Small int data type because we know the value in look up table could not go beyond the tiny int & small int max limit.
In similar way we have applied all the not null constraint to require field provide proper data type.
Please see fig below.
For more detail you can download script for Address book.
Thanks & Esteemed Regards
Rajat Jaiswal
Designing database is one of the most interesting works but on the same time it should be proper because it is base of any business application. We should follow Microsoft best practices while designing the database. Here I am with a simple database design (Address book) concept. I will try to put my best to use Microsoft best practices while designing database. I know you are thinking Address book is so much easy to design, so my answer is yes you are right you can design database easily but using Microsoft best practices it bit more important and I am trying for those best practices.
So first best practice is
1)Define proper data type :-
Most of the time we design database but we ignore proper database but it should not because when you talking for very large scale database application (VLSDB) then wrong data type will give you space problem. According to best practices choose smallest data type first (if it fit in your requirement).We understand this by an example suppose you designed a table with name “seed Data” in which column with name lngId having data type float and float consume 8 bytes and if the seed data cannot exceed more than 10 rows then we should use Tinyint data type instead of float data type because tinyint consume only 1 byte.
2)Define proper Primary & Foreign key:-
According to best practices we should make database normalized and for normalized database we should create proper Primary & Foreign keys. By creating proper primary & foreign keys we get two advantage 1) data anomalies chances reduce we get fast response as well after defining primary key (because cluster index created on primary key)
3)Define proper constraints :-
Microsoft best practices also suggest defining proper constraints for column like not null, unique key constraint on columns so that data anomalies will reduce and we get proper data.
4)Define partition :-
If your database is going to be very large then define proper partition both horizontally & vertically.
5)Normalization: - Database should be proper normalized.
In our Address Book database example we have categorized the data table in 3 categories
1)Lookup table having prefix “lku”
The lookup table is mainly for seed value or we can say this table contains all the data which just act like pre pop data. We have following tables for our Address book
lkuCountryMaster,lkuStateMaster,lkuCityMaster,lkuPhoneType,lkuAddressType,lkuPrefixMaster,lkuURLType,lkuDesignationType,lkuRelationShipType
2)Link table having prefix “lnk”
By the name it is clear that its main purpose is making relation between main data record and other data. We have used following tables lnkPhoneToPerson,lnkAddressToPerson,lnkAddressToCompany,lnkURLToPerson,lnkPersonToCompany,lnkPersonRelations,lnkPhoneToCompany
3)Main table which start with prefix “tbl”
The main table indicates by “tbl” in our Address book database we have used following tables tblPerson, tblAddresses, tblPhotos and tblCompany.
In the entire lookup table we have preferred tiny int & Small int data type because we know the value in look up table could not go beyond the tiny int & small int max limit.
In similar way we have applied all the not null constraint to require field provide proper data type.
Please see fig below.
For more detail you can download script for Address book.
Thanks & Esteemed Regards
Rajat Jaiswal
Subscribe to:
Posts (Atom)