[go: up one dir, main page]

0% found this document useful (0 votes)
4 views2 pages

MYSQL Codes

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

MYSQL Codes

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

mysql> CREATE DATABASE Students; ---(creating a new database)---

mysql> USE Students ---(using database)---

mysql> CREATE TABLE Information (firstname VARCHAR(20),lastname VARCHAR(20),gender


CHAR(1),grade INT(10), dob DATE); ---(creating a new table)---
mysql> SHOW TABLES; ---(show the number of tables in the database)---

mysql> INSERT INTO Information VALUES ('Amanda','Williams','f','10','1999-03-30');


mysql> INSERT INTO Information VALUES ('Peter','Williams','m','10','1998-03-15');
mysql> INSERT INTO Information VALUES ('Cristie','Wills','f','10','1999-02-05');
---(inserting values to a new table)---

mysql> INSERT INTO Information rollnumber VALUE ('001');


mysql> INSERT INTO Information rollnumber VALUE ('002');
mysql> INSERT INTO Information rollnumber VALUE ('003');
---(inserting value to a particular column)---

mysql>SELECT * FROM Information;


---(select all info )---

mysql> ALTER TABLE Information ADD COLUMN rollnumber INT(10);


---(add new column)---
mysql> ALTER TABLE Information ADD PRIMARY KEY(rollnumber);
---(add primary key to column)---
mysql> ALTER TABLE Information DROP column_name;
---(deleting a column)---
mysql> ALTER TABLE Information CHANGE GROSS(old col) SALARY(new col) INTEGER;
---(changing column name)---
mysql> ALTER TABLE Information MODIFY GRADE VARCHAR(2);
---(changing datatype )---
mysql> ALTER TABLE Information DROP PRIMARY KEY;
---(deleting primary kep from column)---

mysql> SELECT * FROM Information WHERE lastname = 'Williams';


---(selection with conditions)---
mysql> SELECT DISTINCT(GENDER) FROM INFORMATION;
mysql> SELECT ECODE AS “EMPLOYEE_CODE” FROM INFORMATION;
mysql> SELECT * FROM INFORMATION WHERE GRADE IN (‘A1’ , ‘A2’);

mysql> SELECT JOB, COUNT(*) FROM INFORMATION EMPLGROUP BY JOB ;


mysql> SELECT DEPTNO , SUM(SAL) FROM INFORMATION GROUP BY DEPTNO ;

mysql> UPDATE Information SET dob = '1999-02-02' WHERE lastname = Wills;


---(updating with conditions)---
mysql> UPDATE Information SET GROSS = GROSS +100 ;
mysql> UPDATE Information SET GROSS = GROSS*2 where grade='A1';
---(updating with arithmetic conditions)---

mysql> DELETE FROM table_name WHERE some_column = some_value;


---(deleting with conditions)---

mysql> SELECT * FROM Information ORDER BY last_name asc;


---(displaying by asc and desc order)---
mysql> SELECT * FROM Information ORDER BY last_name desc;

mysql> SELECT * FROM Information WHERE col_name like 'com%';


---(like condition)---
mysql> SELECT * FROM Information WHERE col_name not like 'com%';
mysql> SELECT * FROM Information WHERE col_name like 'a___';
mysql> SELECT * FROM Information WHERE col_name like ‘_e%’;
mysql> SELECT * FROM Information WHERE GROSS IS NULL ;

mysql> SELECT * FROM Information WHERE col_name between 8 and 10;


---(between condition)---

mysql> SELECT min(salary),max(salary), avg(salary), count(salary),sum(salary) from


INFORMATION where condition;

mysql> DROP TABLE table_name;


---(deleting table)---

You might also like