Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Commands in MySQL

various commands used in mysql

Uploaded by

prachi.sk07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Commands in MySQL

various commands used in mysql

Uploaded by

prachi.sk07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DDL COMMANDS

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;

Example: USE SCHOOL;

Command: SHOW TABLES


Purpose: Shows a list of tables present in the current database.

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, Sname varchar(20));

Viewing structure of table:


Syntax : DESCRIBE/DESC <tablename>;

Example: DESCRIBE student;

Creating tables with SQL Constraint :


SQL Constraint:
A Constraint is a condition or check applicable on a field or set of fields.
NOT NULL/UNIQUE/DEFAULT/PRIMARY KEY
Example:
CREATE TABLE student (Srollno integer NOT NULL, …);
CREATE TABLE student (Srollno integer UNIQUE …);
CREATE TABLE student (Srollno integer NOT NULL, Sclass integer default 12, Sname
varchar(30) );

CREATE TABLE student (Srollno integer NOT NULL PRIMARY KEY, Sclass integer,
Sname varchar(30));

DROP TABLE : command is used to delete tables.


DROP TABLE empl; will remove or delete empl table incuding its structure.

To remove a database the command will be DROP DATABASE empl;

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

Syntax: DELETE FROM tablename Where condition;


Purpose: Deletes data from a table

DELETE FROM Student ;


This command removes complete data from the table

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.

Different forms of Insert Command


1) Inserting data in all the columns
INSERT INTO STUDENT VALUES (1, “AJAY”, 86.50, “A2”, ‘2006/05/14’);

2) Inserting data in specific columns by specifying column names


INSERT INTO STUDENT(RNO, NAME, DOB) VALUES(3,”RASHMI”, ‘2005/07/25’);

3) Leaving a column blank using NULL Keyword (NULL represents empty column)
INSERT INTO STUDENT VALUES(10, “RACHIT”, NULL, NULL, ‘2005/03/10’);

You might also like