Monday, June 1, 2009

Launch MySql:

from command prompt:
  • Goto Start->All Programs->MySql->MySql server 5.1->MySql Command Line Client.
  • It will open MySql prompt(mysql> ).
  • Enter password and proceed.
MySql basic commands are as follows:

  • To list databases:
show databases;
  • To select database:
use database_name;
Ex: use test;

  • To list tables in database:
show tables;

  • To see table schema:
describe table_name;
Ex: describe emptable;

  • To create table:
Ex:
create table if not exists `EMP_MASTER`
(
`EMP_ID` varchar(10) NOT NULL, `NAME` varchar(20), `ADDRESS` varchar(50), `SALARY` NUMERIC(10,2),
constraint SYS_C2516 unique (EMP_ID),
primary key (EMP_ID)
);

  • To insert records in table:
Ex:
insert into `EMP_MASTER` (`EMP_ID`, `NAME`, `SALARY`) values ('1000053003',`JOHN CENA`, 35000.00);

  • To delete all records from table:
truncate table `table_name`;
Ex: truncate table `EMP_MASTER`;
  • To delete table:
drop table table_name;
Ex: drop table `EMP_MASTER`;

No comments:

Post a Comment