Wednesday, June 4, 2014

MySQL Queries Part 1 :: Create database and tables !


Welcome! In this part, you will learn the basics of database. I.e. To create own database, use database, create tables and insert values ..
  • First, get access to MySQL server...

Create a database :

To create a database, first see weather database you are going to create already exist or not. If it exists then you cannot create the database with same name..
To see the list of database, simply type show databases;


To create a new database, type create database [database_name]
Example : Create database bba;
Above code will create a database bba in MySQL server...

Create a table inside database :
To create a table or work inside a database, first u need to enter inside a database you want to interact.. To use the database type use [database_name];
Example : use bba;
To create a table in database, see the example below :

Create table students (id integer primary key auto_increment, name varchar(100), address varchar(200), roll integer unique));
Above code will :
1. Create a table in database with name students !
2. Add a column [id] .. Integer means only numbers are accepted, primary key means main index key on database, auto_increment means that you dont need to insert values in id column everytime. Database will automatically update upcoming records..
3. Add a column [name] with varchar(100) .. varchar means character. It accepts almost everything . (100) means that only 100 words will be accepted in this column.
4. Add a column [address]
5. Add a column roll.. Unique means that values wont be repeated
To see the table you have created, type desc [table_name] 
Example : desc students;

No comments:

Post a Comment