Monday, October 22, 2012

SQL: Remove Multiple Columns from Table

Here is the format which can be used to remove one or more columns from an already existing table:

ALTER TABLE table-name
DROP COLUMN column-name1,
DROP COLUMN column-name2,
DROP COLUMN coloumn-name3

Now lets implement it with a table Student which have following fields:

ID,
First Name,
Last Name,
Middle Name,
Address

Lets say we want to remove Middle Name

So we will use the following query:

ALTER TABLE Student
DROP COLUMN Middle Name


Lets say we want to delete both Middle Name and Address then we use this query:

ALTER TABLE Student
DROP COLUMN Middle Name,
DROP COLUMN Address

Hope you have got the idea how to delete the columns from an existing table.



 

SQL: Create Table

Creating a Table using SQL script is quiete easy. Below is the format using which you can create a Table:

CREATE TABLE table_name
(
column-name1 data-type,
column-name2 data-type,
column-name3 data-type,
column-name4 data-type,
column-name5 data-type,
)

Now lets create a sample table names Student using this format:

CREATE TABLE Student
(
ID int,
First Name varchar(50),
Last Name varchar(50),
Middle Name varchar(50),
Father Name varchar(50),
Address varchar(255),
DateOfBirth datetime
)

So its easier to create any table following this template.


ASP.Net MVC 4 Download

Here is the link for downloading ASP.Net MVC 4 download to work on MVC 4 projects using Visual Studio 2010.

http://www.microsoft.com/en-pk/download/details.aspx?id=30683
File Size : 36  MB

Download and install.

After installation you will get the MVC 4 project option in the Project Type Selection Form when you go for creating New Web Project.

Saturday, October 13, 2012

SQL: Add Column in Table

Here  is the statement skeleton for adding new column in an existing table.

ALTER TABLE table_name
ADD column_name datatype

Lets explain it using an example:

Lets suppose I have a table Student and I want to add new column in it named CourseName.

ALTER TABLE Student
ADD CourseName varchar(50)

A new column gets added to the Student table.

Saturday, October 6, 2012

SQL: String or binary data would be truncated

 Sometimes when you write insert or update query and if get this type of exception:
 
"String or binary data would be truncated. The statement has been terminated."

Dont worry I am going to tell you the solution for this.

This error occurs only when you have a table field that is not big enough to store the data you are inserting in the field.

Example:
Let say you have a table Student with following fields:
ID int
Name varchar(10)

Let say we are going to insert a record in this Table using following query:
insert into Student (ID, Name) 
Values(1, "Name with More Than 10 Characters")

If you execute this query you get the above discussed error since the field Name in Student table has capacity for 10 characters only and you are trying to insert a value which is more than 10 characters.

Solution:
There are two solutions for this:

1. Increase the Field capacity big enough to store the values in database.

2. You can truncate the string value which you have been inserting to fit the field capacity in database. I am going to use the above example again with little change:

insert into Student (ID,Name)
Values (1,cast('Name with More Than 10 Characters' as varchar(10)))

The issue with this solution is that the value that gets stored in database will be only 10 characters:
"Name with  "

So its upto you how you want to handle your problem using any of the solution.

 

 
 

Wednesday, October 3, 2012

Application: MPZ File Copier

I have developed a File Copier Application which is a Desktop Application and it has the following features:
  1. Folder to Folder Copying
  2. Folder to Partition Copying
  3. Partition to Partition Copying
  4. Destination Change Option if Less Space on Disk
  5. Option to Copy Data with Less Disk Space
  6. System Shutdown option after Copying Process
  7. Installer for installing the Application
Operating System Support:
- Windows 2000
- Windows XP
- Windows Vista
- Windows 7
- Windows Server 2000, 2003, 2007

 Here is the download Link to download:

MPZ File Copier Download

I need your suggestions for more features and report any errors if found on below email address:
myprogrammingzone@gmail.com