Commands in MySQL
Commands in MySQL
Creating a Database :
Syntax : CREATE DATABASE SCHOOL; (SCHOOL is the name of a database)
Accessing Database in MySql : Through USE keyword we can start any database
Syntax:
USE database Name;
CREATING TABLE IN MYSQL:Through Create table command we can define any table.
Syntax: CREATE TABLE tablename(columnname datatype(Size),……..);
CREATE TABLE student (Srollno integer NOT NULL PRIMARY KEY, Sclass integer,
Sname varchar(30));
DML COMMANDS
INSERTING DATA INTO TABLE : The rows are added to relations using INSERT command.
INSERT INTO tablename VALUES (value, value,…);
INSERT INTO student VALUES (100,’ABC’);
Command: DELETE
DELETE FROM Student where srollno = 5; removes rows on the basis ofcondition
Data Types : are means to identify the type of data and associated operations for handling it.
The data types are divided into three categories : Numeric, Date and Time, and String type.
Difference between Char and Varchar :
The CHAR data type specifies a fixed length character string whereas VARCHAR,
specifies a variable length string.
For example, a column with datatype char(10) specifies that all the values stored is this column
have size 10. If a value is shorter than length 10, then blanks are added to make the length of
this column as 10.
Whereas when a column is given datatype as VARCHAR(10), then the maximum size a
value in this column can have is 10. If the length of any value is shorter than 10 then no blanks
are added.
3) Leaving a column blank using NULL Keyword (NULL represents empty column)
INSERT INTO STUDENT VALUES(10, “RACHIT”, NULL, NULL, ‘2005/03/10’);