Create Backup of Single Table in Same Database Or Alter Table Column Or Add New Column

Sometime you required to erase all your data from application table but you don’t want to loos your precious data. there are two ways to take backup of data.

  • first, To take backup of whole database, which contains .mdf file and log file.
  • second, to take only one table backup in same database.

To take one table back in same database use following query.

SELECT * INTO <NEW TABLE NAME> FROM <OLD TABLE NAME>

NEW TABLE NAME – BACK UP TABLE NAME (I.E.NEW TABLE)

OLD TABLE NAME – NAME OF THE TABLE YOU WANT TO TAKE BACKUP

Add New Column in Table Use following Query:

ALTER TABLE <TABLENAME>
ADD <COLUMN NAME> <DATA TYPE> <NULL / NOT NULL>

Alter Table Column, Use following Query:

ALTER TABLE <TABLE NAME>
ALTER COLUMN <COLUMN NAME> <DATA TYPE>

HAPPY QUERYING…:)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s