Archive for the ‘Sql Server’ Category

1
Dec

Sql Server Short Cuts

   Posted by: admin   in Sql Server

Hello Sql Server developer here is some nice short cuts which increase your developing speed and reduce development time.

Create New File :- CTRL+N

Open File :- CTRL+O

Read the rest of this entry »

Hello Friends,

When ever some one ask question like that how to insert data from one table to another our mind strikes and give answer that create one cursor which will access all data from one table and insert in to anothre table.sorry friends i give some nice solution then right now you have.

First Method to do such kind of stuff.

This method is used when table is already created in the database earlier and data is to be inserted into this table from another table.

First table which is allready created name is test_from.

Create New Table which have Name test_to.

CREATE TABLE test_to (FirstName VARCHAR(100), LastName VARCHAR(100))

INSERT INTO test_to (FirstName, LastName)

SELECT FirstName, LastName FROM test_from WHERE id = 2

Second Method

This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.

SELECT FirstName, LastName INTO test_to FROM test_from WHERE id = 2

Enjoy Friends.


8
Oct

Import XML data into sql server table

   Posted by: admin   in Sql Server

Hello friends some guys asking me about is this any way to imports XML data into sql server table.

so friends here is answer of your question please follow the step and you will fill happy after task will done.
Step 1: Create  one table in the

CREATE TABLE Customer (ID int NOT NULL, Name xml)

Step 2: Then After  create a XML file .

<?xml version=”1.0″ encoding=”UTF-8″?>
<Customers>
<Customer ID=”1″>
<Name>Test</Name>
</Customer>
</Customers>

<Customers>
<Customer ID=”2″>
<Name>Data</Name>
</Customer>
</Customers>

Save this XML file name as test.xml into C:\ drive of your computer.

Step 3: Now import the xml data from C:\test.xml into  newly created table ‘Customer’

INSERT INTO Customer(ID, Name)
SELECT 1, Name
FROM
(
SELECT * FROM OPENROWSET(BULK ‘c:\test.xml’,SINGLE_BLOB) as Disc
) AS ImportXML (Disc)

Note: Do not forget to specify the UTF-8 encoding scheme in the XML file.

Enjoy Friends.

8
Oct

find out logged users in to a SQL Server 2005

   Posted by: admin   in Sql Server

Hello Guys and Girls what i servers you is some nice thing for sql server users.

if you want to find out the users logged in a database then we have to use some of system views.

sys.sysprocesses is one of them.

select * from sys.sysprocesses;

it will returns the host name , login name , window user name and processes.

if you want to know more stuff of  sys.sysprocesses then go here

http://msdn2.microsoft.com/en-us/library/ms179881.aspx

some more Store procedures provides same stuff

EXEC sp_who

EXEC sp_who2

sp_who provides information about current users, sessions, and processes in an instance of SQL Server.

Enjoy Friends

hello frineds if you need to know that how much space occupied by your each tables which was created by you.

this is the shortest way for any sql server user.

USE yourdatabasename
EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused ‘?’”

Enjoy all guys and girls.

Hello Friends one requriment face last days from my boss was he said me that get all active connection in any database in sql server. mean give me list of all user which are currently connected to the our live database.

so fullfill this requriment with below solution so please write this query it will make your boss happier also

this query is for all database on server.

SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,
loginame as LoginName
FROM sys.sysprocesses
WHERE dbid > 0
GROUP BY dbid, loginame

please tell your boss and get increment in your salary.

Hello Friends many People install sql server 2005 and then after they want to change system admin password mean “sa” password.

i give you two way to change “sa” password one is if you don`t know the password then do following stuff in your query window.
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
USE [master]
ALTER LOGIN [sa] WITH PASSWORD=N’NewPassword’

Second Way is you may be  remember your Old Password and want to change the ’sa’ password then do following stuff.

ALTER LOGIN [sa] WITH PASSWORD = N’MyNewPassword’ OLD_PASSWORD = ‘MyOldPassword’;

Enjoy Boys and Girls.