0% found this document useful (0 votes)
46 views

Mysql Queries

Mysql commands for creating, modifying, and manipulating databases and tables. Key commands include: 1) CREATE DATABASE to create a new database. CREATE TABLE to define a new table within a database with column names and data types. 2) INSERT INTO to add data to tables. SELECT statements to query data from tables. 3) UPDATE to modify existing data within tables. DELETE to remove rows from tables. 4) ALTER TABLE to modify table and column definitions, DROP to remove columns and tables.

Uploaded by

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

Mysql Queries

Mysql commands for creating, modifying, and manipulating databases and tables. Key commands include: 1) CREATE DATABASE to create a new database. CREATE TABLE to define a new table within a database with column names and data types. 2) INSERT INTO to add data to tables. SELECT statements to query data from tables. 3) UPDATE to modify existing data within tables. DELETE to remove rows from tables. 4) ALTER TABLE to modify table and column definitions, DROP to remove columns and tables.

Uploaded by

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

Mysql

#To comment any query or information use # before that

#To create database


create database databasename;

#To create any duplicate copy of any database


create database test_copy; ... here original database is "test"

#To remove database


drop database databasename;

#To create table


create table if not EXISTS tablename (columnname datatype UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY,columnname2 datatype2);

eg.live query in mysql----

####create database bhai;


####use bhai;
####CREATE TABLE `Bhai`.`emp` (
`EmpID` INT NOT NULL,
`Empname` VARCHAR(45) NULL,
`salary` DECIMAL(10,2) NULL,
PRIMARY KEY (`EmpID`));

eg.
create table products (prod_id INT, prod_code CHAR(4), name VARCHAR(50), quantity
INT DEFAULT 0, price DECIMAL(10,2), PRIMARY KEY (prod_id));

#To insert values in tables


INSERT INTO databasename.tablename(columnname1, columnname2, ..) VALUES(value1,
value2, ..);
eg.insert into bhai.employee (EmpID,Empname,sal,phone_no) values
(201,'Vivek',23000,8378029402);

#For bulk record insertion


insert into bhai.employee values (202,'Rutvik',24000,8278029402),
(203,'Ram',30000,9834410698);
or
insert into bhai.employee (EmpID,sal,phone_no) values (204,25000,5555511111),
(205,26000,2222211111),(206,17000,4444411111);

#select statement
select * from bhai.emp;

select * from databasename.tablename where columnname not LIKE 'Blu__%';

#Update record in mysql


update databasename.tablenme set columnnametoupdate=Value where
columnnameforrefrence=value;
eg.update bhai.employee set Empname='Rahul',phone_no=6666612345 where EmpID = 204;

# delete perticular record


eg. delete from bhai.employee where Empid=205;

#Alter Statement
alter table bhai.emp add phone_no varchar(10) not null;
eg.alter table bhai.emp add lastname varchar(10) not null after FIRSTNAME; ----
it will generate column after firstname col.

#To delete perticular column


alter table databasename.tablename drop column columnname;
eg. alter table bhai.emp drop column firstname;

#Modify datatype/constraints to other datatype/constraints of any column


alter table databasename.tablename modify columnname newdatatype;
eg.alter table bhai.emp modify salary varchar(111);

#To show all information (descriptions) of tables


describe databasename.tablename;

#To rename tablename in mysql


alter table databasename.tablename rename to databasename.newtablename;
eg. alter table bhai.emp rename to bhai.employee;

#To rename columnname along with changing datatype/constraints in mysql


alter table databasename.tablename change columnname datatype newdatatype;
eg. alter table bhai.emp change salary sal decimal(10,2);

#Truncate the table in mysql


truncate table databasename.tablename; ---- it will delete all data inside table
but keep structure as it is.

#Drop the table in mysql


drop table databasename.tablename; ---- it will delete all data as well
structure of table

#IN Operator
select * from users where fname IN ('Meet','Shivam','Jay');

#Order By and LIMIT clause


slect * from products ORDER BY price LIMIT 3,4; ----With LIMIT clause it will
remove first 3 entries and shows only 4 entries which comes after 3.

#To comment any query in mysql as


/* */ ------for multiple line comment
"#" ------for sigle line comment

You might also like