Showing posts with label SQL SERVER. Show all posts
Showing posts with label SQL SERVER. Show all posts

Database restore from SQL Server 7 ,SQL Server 2000 to SQL Server 2005

it is possible to restore database from sql server 7, sql server 2000 to sql server 2005.
it can be achieved by using restore and with replace command

use master

restore database mydatabase from disk ='c:\mybackup.bak' with replace

Sql Server – Backup and Restore Database using SQL Script (T-SQL)

it is easy to take backup in sql server using script without any External tools.
By SIMPLE ways.. as follows...

use master

create database mydatabase

backup database mydatabase to disk ='c:\mybackup.bak'

Yeah,i can be easily restore by simple steps...

use master

restore database mydatabase from disk ='c:\mybackup.bak'

thats all..

SQL Server 2000 Workload Governer


Workload governor limits the performance of MSDE if the SQL engine receives more load than limit of MSDE(8 Cuncurrent connection).

Workload governor sits between the client and the database engine and counts the number of connections per database instance. If Workload governor finds that the number of connections exceeds eight connections, it starts stalling the connections and slowing down the database engine.

It does not limit the number of connections but makes the connection request go slow. By default 32,767 connections are allowed both for SQL SERVER and MSDE.

Difference between MSDE and SQL Server 2000

MSDE(Microsoft Desktop Engine):

MSDE is a cut down version of the SQL SERVER database and free, redistributable software.

Differences:

A.Size:

In MSDE database size limited to 2GB.
In SQL Server database size limited to 1,048,516 TB1(1 Billion GB).

B.Performance:

Performance of MSDE degrades when maximum number of concurrent operations greater then or equal to 8. Performance degradation is implemented with the help of SQL SERVER 2000 workload governor.

In SQL SERVER 2000, possible number of concurrent connections are 32,767.

C.OLAP and Data warehousing:

MSDE does not provide OLAP and Data warehousing capabilities.

D.Mail:

MSDE does not have support facility for SQL mail.

E.Administrative Tools:

MSDE doesn't have its own administrative tools. There are many third party tools, which provide administrative capability GUI.

SQL Server have administrative tools such as enterprise manager, Query analyzer or Profiler.

Ref : www.codeproject.com/

Difference between Rule and Check Constraint

Check Constraint:

Check constraint is associated with columns in a Table. So these can't be re-used.

Suppose if "Emp" table having the coulmn "Salary" then
alter table Emp add constraint ck_op Check (Salary between 15000 and 45000)

Rule:

Rules are defined with in a database and can be applied to any number of columns.
Creating Rule:
CREATE RULE SAL_RANGE
as
@Sal > 15000 and @Sal > 45000
Binding Rule to a Column:
SP_BINDRULE 'SAL_RANGE','Emp.Salary'


Step by step process of getting connection string from web.config

Getting Connection string from web.config
In web.config file you find tag like this

<connectionStrings/>

We have to write a connection in connectionstring tag so that we can use in our application.

Steps are

1.replace <connectionStrings/> by

<connectionStrings>
</connectionStrings>

2.add connection string to this tag
Sql Authentication Connection,you have the user name and passwords of ur database

<add name="ConnectionStringName" connectionString="Data Source=.\Sqlexpress;Initial Catalog=databasename;User ID=databaseuserid;Password=databasepassword" providerName="System.Data.SqlClient"/>

Windows Authentication Connection default settings of Sqlserver2005

<add name="ConnectionStringName" connectionString="Data Source=.\Sqlexpress;Initial Catalog=databasename;integrated security=SSPI" providerName="System.Data.SqlClient"/>

Just u have to replace User ID=databaseuserid;Password=databasepassword to
integrated security=SSPI that’s all for Sql Authentication to Windows Authentication

It look like this

<connectionStrings>
<add name="ConnectionStringName" connectionString="Data Source=.\Sqlexpress;Initial Catalog=databasename;User ID=databaseuserid;Password=databasepassword" providerName="System.Data.SqlClient"/>
</connectionStrings>

or

<connectionStrings>
<add name="ConnectionStringName" connectionString="Data Source=.\Sqlexpress;Initial Catalog=databasename;integrated security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>

3. Getting Connection from web.config using c#

Add fallowing Namespace to your application

using System.Web.Configuration;
using System.Data.SqlClient;

Code for getting connection

SqlConnection sqlConn = null;

String str=
WebConfigurationManager.ConnectionStrings["ConnectionStringName"].ToString();

// Note:Ensure ConnectionStringName is same we mentioned in web.config file that all

sqlConn = new SqlConnection(str);
sqlConn.Open();

// do operation

sqlConn.Close();

Enjoy this coding…

How to change from Windows Authentication to SQL Server Authentication for SQLExpress 2005

While installing SQL Express, we have to specify Sql Authentication mode and specify password for sa otherwise Windows Authentication mode being enabled (it is a default mode). To change mode we have to perform the following steps to change to SQL Server Authentication, using the sa (system administrator) account

1) Enable SQL Server Authentication by executing: "ALTER LOGIN sa ENABLE", or by using the Microsoft SQL Server Management Studio Express application.

2) Change/set the password for the sa account by executing: "ALTER LOGIN sa WITH PASSWORD = 'yourpassword'"

3) Stop the SQL Server service

4) Open regedit, go to the "HKLMSoftwareMicrosoftMSSqlserverMSSqlServer" entry and set the LoginMode value to 2.

goto start->run-> type regedit
goto search window find LoginMode
it will show in sqlserver entry set LoginMode 2


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServerLoginMode 2

5) Restart the SQL Server service

Delete Vs Truncate(SQL Server)

• Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

• Truncate table also deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

• Truncate table is functionally identical to delete statement with no “where clause” both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

• Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.

• In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

• If you want to retain the identity counter, use delete statement instead.

• You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause.

• Truncate table cannot activate a trigger(Any trigger created aganist Delete operation).

• Truncate table may not be used on tables participating in an indexed view.

Update Statement Between Two Tables

"T1" is the table having the fields of id and name. There is another table "T2" having id and PetName with some additional information. Now to update "T1".name with "T2".PetName.
Update query is as follows(condition between two tables),
update T1 set t1.name = T2.PetName
from T2
where T1.id = T2.id

SQL Server - Insert multilingual data in table

You need the N'' syntax only if the string contains characters which are not inside the default code page.

"Best practice" is to have N'' whenever you insert into an nvarchar or ntext column.
"Unicode string constants that appear in code executed on the server, such as in stored procedures and triggers, must be preceded by the capital letter N. This is true even if the column being referenced is already defined as Unicode. Without the N prefix, the string is converted to the default code page of the database.

This may not recognize certain characters.The requirement to use the N prefix applies toboth string constants that originate on the server and those sent from the client."

Like:
create table mul (lang nvarchar(200))
insert into mul (lang ) values (N'multilingual unicode strings')
insert into mul (lang ) values (N' தமிழ்'
)
insert into mul (lang ) values (N' 請提供服務的日期進行')

use nVarChar as the column data type.

How to fix SQL Server Error 3154: The backup set holds a backup of a database other than the existing database.

Fix/Solution:

Use WITH REPLACE while using the RESTORE command.

RESTORE DATABASE abc FROM DISK = 'C:\backup.bak' WITH REPLACE

In this example abc is one database,backup.bak is backup of abc.

How to Recover Suspected Database in SQL Server 2000

If a database is marked suspect it cannot be accessed and hence nothing can be performed in the database. A database can be marked suspect for one of the following reasons,

a.If one or more database files are not available.
b.If the entire database is not available.
c.If one or more database files are corrupted.
d.If a database resource is being held by the operating system.

In order to recover the suspected database, sysdatabases status is modified in master database.Before you do any changes with system table run the following command to enable adhoc changes to the system tables.

use master

go

sp_configure allow, 1

go

reconfigure with override

go

sp_resetstatus ‘DatabaseName’

go

After the procedure is run, immediately disable updates to the system tables:

sp_configure 'allow updates', 0

GO

RECONFIGURE WITH OVERRIDE

GO

Then Stop and Restart ALL SQL Server Services.

If the database still goes back into suspect mode, and you can't fix the original problem, and you have no recent backup, then you can get information out of the database by putting it into Emergency Mode. If you do this, extract the data/objects out with DTS and rebuild the database.

The following command to put the database into emergency mode

USE master

GO

sp_configure 'allow updates', 1

GO

RECONFIGURE WITH OVERRIDE

GO

UPDATE master..sysdatabases SET status = 32768 WHERE name = 'DatabaseName'

GO

sp_configure allow, 0

go

Stop and Restart ALL SQL Server Services.

We are now ready to pull whatever data we can out of the tables in the corrupt database. Remember, some tables may be corrupt, thus you may have to play with various T-SQL statements to get the data out. First try DTS using EnterprisesManager.

These are the steps necessary to export data out of the corrupt database into the new:

a. Create a new production DB, or a temp DB, to have a place to export whatever data we can out of the corrupt db.

b. Start a DTS operation by going into EM and drilling down to “Data Transformation Services” … “Local Packages”.

c. Open a NEW DTS package by right-mouse clicking …

d. When DTS opens, choose “Copy SQL Server Objects Task” from the Connection Icons. Enter in a description like “Export Corrupt Data”. Enter in the SA/pass combination as well as the CORRUPT database from the drop-down.

e. Select the “Destination” Tab. ”. Enter in the SA/pass combination as well as the PRODUCTION database from the drop-down.

f. Select the “Copy” Tab. UNCHECK the “Create destination objects” box. UNCHECK the “Copy all objects” box and then Click on the “Select Objects” Button. This brings up the “Select Objects” screen.

g. CHECK ONLY “Show all tables” like shown above. Then check each table that needs to be exported. If ALL tables need to be export, Click on the “Select All” button. Click OK.

h. Click OK again and we are done creating this task. Now we execute the package by Clicking the green arrow on the menu bar.

REF : http://www.tek-tips.com/