Showing posts with label Database Info. Show all posts
Showing posts with label Database Info. Show all posts

Monday, March 29, 2010

Shrinking File Log – SQL Server with SQL Script

When you monitoring your physical database (SQL Server) you will find file .LDF on big size . It because that file contain your transaction log on your daily operation on database.


And sometime if your harddisk capacity is become out of space, and sometime it make your operational transaction become fail to execute. So you need to execute some script to handle it.

-- 1.to know database information
sp_helpdb YourDBName
-- after that you will find your log file
-- 2.to do shrinkfile action
DBCC SHRINKFILE(YourDBName_log)



Sample best practice on our environment :


image 
PS : when i do this script, i use SQL Server 2008





image





Have a nice try, hope it will help you also.






Thursday, January 14, 2010

Running SQLCmd – SQL Server

We can use sql query with interface or we can use it with command prompt, on this time i prefer to discuss from command prompt.

With interface, we can run it from :
image

With command prompt we can run it from
image

The script is like this :
For Window Authentication Login
sqlcmd -S server1\SQLExpress

image

For Account Authentication Login
sqlcmd -S server1\SQLExpress -U SqlUserAccount -P SqlPassword

Refer to SqlCmd utility – Case Sensitive format
image 
And we can try for this useful scripts :
SqlCmd Help
sqlcmd /?

Execute query from file
sqlcmd -S myServer\instanceName -i C:\myScript.sql

Save query result on file
sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt

Reference Link
http://msdn.microsoft.com/en-us/library/ms165702.aspx
http://msdn.microsoft.com/en-us/library/ms170572.aspx

Thursday, July 2, 2009

How to use MonYog for MYSQL

To analysis your database, you can use MonYog application.

Go to this application:
image

This application will display several information:
Disk information – will display file capacity that already use for database
image


Process graphic, connection, cache hit and statement that use:
image
image


and it also handle monitor/advisor:
image

it handle statement also – with graphic support.
image

hope this tool can improve your skill on MySql.

How to use SQLYog for MySQL

When i ask to my friend – Fendy, is there anyway to execute SQL syntax on MySQL.

MySQL without command console (dos), and he answered “you can use SqlFront or SqlYog”, so i prefer SqlYog to to this:

ps: I use SQLYog Enterprise version 7.14 and MySQL 5.0.77
this application will help you to use MySQL GUI more friendly

Go to SqlYog application
image

And the application will show like this
image 

use can write your sql syntax on right template, and result will appear on the bottom template
image

when you want to know the history of your sql syntax, you can use function history – like sql profiler:
image 
when i want to create sp, i can do it, it because i use mysql version 4.12, to create sp or function you must install MySql database >= 5 ( MySQL version)

this is example to create sp:
 image

and to call sp:
image

when i try to alter sp, on SqlYog, it will generate script to drop and create that sp again, the basic flow to alter sp.

The important point is to backup your database, where you can save data and structure on current database:
image

to Restore database, you only click Restore from SQL Dump and choose your backup file.

ok, have a nice Sql Script on MySql.

Wednesday, July 1, 2009

How to use MYSQL Database – command prompt

Today i want to test MySQL database

I use mysql-4.1.22-win32, setup and after install it,  i go to 
image 

and it will display this window (need password) if you use it setting :
image 
default window will appear like this:
image 
after that we learn about command syntax on mysql

to know mysql version we can use this syntax:
mysql> select version();

image

to display database that exist:
mysql> show databases;
image

to create new database:
mysql> create database practise01;
image

to change to database that you want to choose:
mysql> use practise01;
image

to create new table:
mysql> create table tblTest01(id int);
image

to show table structures:
mysql> describe tbltest01;
or
mysql> show columns from tbltest01;
image

to show tables that exist:
mysql> show tables;
image

to alter table structure:
mysql> alter table tbltest01 add nama varchar(20);
image

to fill your data table:
mysql> insert into tbltest01(id,nama) values(1,"jimon");
point : insert into tablenm(col1,col2,…) values(datacol1,datacol2,…)
image 

to display data from current table:
mysql> select * from tbltest01;
image 

to update data from current table:
mysql> update tbltest01 set id=3,nama="cyntia" where nama="cintia";
image

to close window mysql command prompt:
mysql> exit;

ok have a nice try, hope this will help you to know mysql better.

Hukum Tabur Tuai

Ingatlah hukum dasar ini, dalam kehidupanmu  Barang siapa yang menanam, dia pula yang akan menuai