0% found this document useful (0 votes)
2 views4 pages

MySQL Commands

This document provides an overview of various MySQL commands including creating and using databases, creating and modifying tables, and performing data manipulation operations such as INSERT, UPDATE, DELETE, and SELECT. It includes syntax examples for each command, demonstrating how to create tables, add or drop columns, and manage constraints. The document serves as a quick reference guide for executing basic SQL operations in MySQL.

Uploaded by

nayakarpita82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

MySQL Commands

This document provides an overview of various MySQL commands including creating and using databases, creating and modifying tables, and performing data manipulation operations such as INSERT, UPDATE, DELETE, and SELECT. It includes syntax examples for each command, demonstrating how to create tables, add or drop columns, and manage constraints. The document serves as a quick reference guide for executing basic SQL operations in MySQL.

Uploaded by

nayakarpita82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MySQL Commands

Create Database

Create Database Database_name;

Use of database

Use database_name;

Table creation

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);

Example:- create table Employee(Employee_ID int(10),Employee_Name varchar(20),Job_Title


varchar(20),Salary integer(10),Bonus integer(10),Age integer(10),Manager_ID integer(10));

The SQL DROP TABLE Statement


The DROP TABLE statement is used to drop an existing table in a database.

DROP TABLE table_name;


Drop table Employee;

ALTER TABLE - ADD Column


ALTER TABLE table_name
ADD column_name datatype;

Example:-

ALTER TABLE Customers


ADD Email varchar(255);

DROP COLUMN
The DROP COLUMN command is used to delete a column in an existing table.

ALTER TABLE table_name


DROP COLUMN column_name;

Alter table Employee drop column Employee_Name;


ALTER TABLE - RENAME COLUMN
ALTER TABLE table_name
RENAME COLUMN old_name to new_name;

Example-Alter table Employee rename column Salary to Salary1;

ALTER/MODIFY DATATYPE
ALTER TABLE table_name
MODIFY column_name datatype;

Example –Alter table Employee modify Employee_id intiger(20);

DROP CONSTRAINT
ALTER TABLE Persons
DROP CONSTRAINT UC_Person;

ADD CONSTRAINT Keyword


ALTER TABLE Table_name
ADD CONSTRAINT PRIMARY KEY (column_name);
Example-alter table Employee add constraint primary key(Employee_ID);

INSERT INTO Statement


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of
the values is in the same order as the columns in the table. Here, the INSERT
INTO syntax would be as follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

SQL DELETE Statement


The DELETE statement is used to delete existing records in a table.

DELETE Syntax
DELETE FROM table_name WHERE condition;

Delete All Records


It is possible to delete all rows in a table without deleting the table. This means
that the table structure, attributes, and indexes will be intact:

DELETE FROM table_name;

The SQL UPDATE Statement


The UPDATE statement is used to modify the existing records in a table.

UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

SQL SELECT Statement

Syntax
SELECT column1, column2, ...
FROM table_name;

Select ALL columns


If you want to return all columns, without specifying every column name, you
can use the SELECT * syntax:
Example
Return all the columns from the Customers table:

SELECT * FROM Customers;

You might also like