Tuesday, March 1, 2011

Creation of SQL DATABASE using COMMAND PROMPT

Hi Friends,In this Article we will discuss the creation of sql database using Command lineIn Windows Operating System,First we have to click on the Start button and then click Run and Type cmd in Run command and press ok



For, Access the Database 
-----------------------------

Type the following command in the command prompt

C:\Program Files\Microsoft SQL Server\90\Tools\Binn>SQLCMD -SUSER\SQLEXPRESS -E
Where USER\SQLEXPRESS is the server name and -E for Windows Authentication
if you have username and password change the following code as
C:\Program Files\Microsoft SQL Server\90\Tools\Binn>SQLCMD -SUSER\SQLEXPRESS -Usa -P******
now press Enter (you will get like this...)
1>use MyDatabase (write your Database name)

2>SELECT * from Employeedata (Write the Query)

3>Go
and press Enter

then you will get like this...

EMPID EMPLOYEENAME
----- ------------ ----------------
1 francis
2 taanu
3 joe
4 benq
5 sarat



(5 rows affected)

In The Above -U is username and -P password

For,Save the Result in Text File 
------------------------------------

if you want save this result as a text file, follow the steps ...
C:\Program Files\Microsoft SQL Server\90\Tools\Binn>SQLCMD -SUSER\SQLEXPRESS -o E:\filename.txt

1>use MyDatabase

2>select * from Employeedata
3>go
and press Enter...

Now check the file filename.txt in the E drive.

For,Restore Database 
-------------------------
C:\Program Files\Microsoft SQL Server\90\Tools\Binn>SQLCMD -SUSER\SQLEXPRESS -E

1>RESTORE DATABASE MyDatabase FROM DISK='E:\joe.MDF'

2>Go
For,BackUp Database 
-------------------------
C:\Program Files\Microsoft SQL Server\90\Tools\Binn>SQLCMD -SUSER\SQLEXPRESS -E

1>BACKUP DATABASE MyDatabase TO DISK='E:\joe.MDF'

2>Go
and press Enter

then you will get a message like BACKUP DATABASE successfully processed in 0.180 seconds (7.271 MB/sec)

Thats it friend...

developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home