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

SQL Basic Commands

Uploaded by

Madhushree S G
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)
18 views

SQL Basic Commands

Uploaded by

Madhushree S G
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/ 5

MySQL Commands

mysql –u root -p

password: password

 show databases;
 create database Program1;

1. SELECT — extracts data from a database

SELECT column_name
FROM table_name;

SELECT statements fetch data from a database.

2. UPDATE — updates data in a database

UPDATE table_name
SET some_column = some_value
WHERE some_column = some_value;

UPDATE statements allow us to edit rows in a table.

3. DELETE — deletes data from a database


DELETE FROM table_name
WHERE some_column = some_value;

DELETE statements remove rows from a table.

4. INSERT INTO — inserts new data into a database

INSERT INTO table_name (column_1, column_2, column_3)


VALUES (value_1, ‘value_2’, value_3);

INSERT statements add a new row to a table.

5. CREATE DATABASE — creates a new database

CREATE DATABASE databasename;

CREATE DATABASE statements create a new SQL database.

6. ALTER DATABASE — modifies a database

ALTER DATABASE database_name


[COLLATE collation_name ]

ALTER DATABASE statements change the characteristics of a


database.

7. CREATE TABLE — creates a new table


CREATE TABLE table_name (
column_1 datatype,
column_2 datatype,
column_3 datatype
);

CREATE TABLE statements create a new table in the database.

8. ALTER TABLE — modifies a table

ALTER TABLE table_name


ADD column_name datatype;

ALTER TABLE statements add, delete, or modify columns in an


existing table.

9. DROP TABLE — deletes a table

DROP TABLE table_name;

DROP TABLE statements drop an existing table in a database.

10. CREATE INDEX — creates an index

CREATE INDEX index_name


ON table_name (column_name1, column_name2…);
Index statements create on existing tables to retrieve the rows quickly.

11. DROP INDEX — deletes an index

ALTER TABLE table_name


DROP INDEX index_name;

DROP INDEX statements delete an index in a table.

Q: Create a database name students.


Create table name Student_details(Sl.no Integer(2), Name Varchar(30), Course
varchar(20), Roll_no varchar(15), DOB(Date));

INSERT INTO Student_details VALUES (1,'LOKESH','MCA',1CD23mc001,’12-01-


1999’);
10 students data you have to insert 5 MBA and 5 MCA.

Solve these questions:


 Show only MCA students.
 Update 1 student from MBA to MCA.
 Alter column from Course to Degree.
 Add new column Marks after Degree column.
 Update the marks of all 10 students.

You might also like