0% found this document useful (0 votes)
76 views11 pages

My SQL Commands - Docx Rajat

The document describes various SQL commands used to create and manage databases, tables, and data in MySQL. It shows commands to create a database and table, insert, select, update, and delete data, as well as commands to describe tables, set primary keys, and add constraints.

Uploaded by

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

My SQL Commands - Docx Rajat

The document describes various SQL commands used to create and manage databases, tables, and data in MySQL. It shows commands to create a database and table, insert, select, update, and delete data, as well as commands to describe tables, set primary keys, and add constraints.

Uploaded by

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

MY SQL COMMANDS

Creating database:

mysql> create database om;

Query OK, 1 row affected (0.00 sec)

1) SHOW DATABASES
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| connectivity |
| dept |
| exam |
| login |
| madhvi |
| marks |
| mysql |
| np |
| om |
| pet |
| practice |
| prithvi |
| search |
| species |
| student |
| sunmacro |
| teachers |
| teensblog |
| test |
+--------------------+
20 rows in set (0.00 sec)

3)USING DATABASES

mysql> USE om;

Database changed

mysql>

4)CREATING TABLES
mysql> CREATE TABLE STUD_1

-> (ROLL_NO INT(3)NOT NULL PRIMARY KEY,

-> NAME VARCHAR (20),

-> GR_NO INT(3),

-> SEX CHAR(1));

Query OK, 0 rows affected (0.06 sec)

5) SHOW TABLE COMMANDS

mysql> SHOW TABLES;

+-----------------+

| Tables_in_om |

+-----------------+

| stud_1 |

+-----------------+

1 row in set (0.00 sec)

6)INSERT COMMANDS

mysql> INSERT INTO STUD_1


-> VALUE('1','Dennis','001','M');

Query OK, 1 row affected (0.03 sec)

7)REORDERING

mysql> INSERT INTO STUD_1(NAME,ROLL_NO,SEX,GR_NO)

-> VALUE('Veronica','3','F','003');

Query OK, 1 row affected (0.03 sec)

8)SELECT COMMANDS(FOR ALL COLOUMNS

mysql> SELECT*

-> FROM STUD_1


-> ;

+---------+---------+-------+------+

| ROLL_NO | NAME | GR_NO | SEX |

+---------+---------+-------+------+

| 1 | Dennis | 1 | M |

| 3 | Veronica | 3 | F |

| 4 | Daniel | 4 | M |

| 5 | Fredrick | 5 | M |

| 6 | Debbie | 6 | F |

+---------+---------+-------+------+

5 rows in set (0.00 sec)

9) SELECT COMMANDS FOR SPECIFIC COLUMNS

mysql> SELECT NAME

-> FROM STUD_1;

+---------+

| NAME |

+---------+

| Dennis |

| Veroica |

| Daniel |

| Fredrick |

| Debbie |

+---------+

5 rows in set (0.00 sec)

10)DISTINCT COMMANDS

mysql> SELECT DISTINCT SEX

-> FROM STUD_1;

+------+
| SEX |

+------+

| M |

| F |

+------+

2 rows in set (0.00 sec)

10)SELECT ALL COMMANDS

mysql> SELECT ALL SEX

-> FROM STUD_1;

+------+

| SEX |

+------+

| M |

| F |

| M |

| M |

| F |

+------+

5 rows in set (0.00 sec)

11) DESCRIBE

mysql> DESC STUD_1;

+---------+-------------+------+-----+---------+----
---+

| Field | Type | Null | Key | Default |


Extra |

+---------+-------------+------+-----+---------+----
---+
| ROLL_NO | int(3) | NO | PRI | NULL |
|

| NAME | varchar(20) | YES | | NULL |


|

| GR_NO | int(3) | YES | | NULL |


|

| SEX | char(1) | YES | | NULL |


|

+---------+-------------+------+-----+---------+----
---+

3 rows in set (0.03 sec)

12)SIMPLE CALCULATIONS:

*) MULTIPLICATION

mysql> SELECT 1*6

-> ;

+-----+

| 1*6 |

+-----+

| 6 |

+-----+

1 row in set (0.02 sec)

+) ADDITION

mysql> SELECT 1+6

-> ;

+-----+

| 1+6 |

+-----+

| 7 |

+-----+

1 row in set (0.00 sec)

13) selecting specific rows


mysql> select * from faculty
-> where fid=1;
+------+-------+---------------+-------+
| fid | fname | qualification | marks |
+------+-------+---------------+-------+
| 1 | aman | b.tech | 0 |
+------+-------+---------------+-------+
1 row in set (0.00 sec)

14) condition based on range

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

15)CONDITION BASED ON LIST

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+
1 row in set (0.00 sec)

16)condition base on pattern

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

17)update commands

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

mysql>

18) searching nulls

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |
+------+-------+---------------+-------+

1 row in set (0.00 sec)

mysql>

19) order by clause

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

mysql>

20)logical operator(||,&&,=!)

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

19) Deleting data

mysql> select * from faculty


-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

21)Alter table command

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

22) drop command

mysql> select * from faculty

-> where fid=1;

+------+-------+---------------+-------+

| fid | fname | qualification | marks |

+------+-------+---------------+-------+

| 1 | aman | b.tech | 0 |

+------+-------+---------------+-------+

1 row in set (0.00 sec)

22) Adding primary key


mysql> create table school(name varchar(100),roll
int PRIMARY KEY , marks int);

Query OK, 0 rows affected (0.33 sec)

mysql> desc school;

+-------+--------------+------+-----+---------+-----
--+

| Field | Type | Null | Key | Default |


Extra |

+-------+--------------+------+-----+---------+-----
--+

| name | varchar(100) | YES | | NULL |


|

| roll | int(11) | NO | PRI | NULL |


|

| marks | int(11) | YES | | NULL |


|

+-------+--------------+------+-----+---------+-----
--+

3 rows in set (0.00 sec)

23) constraints(unique, default,check)

mysql> create table employee

-> (ecode int unique not null ,

-> sex varchar(100) not null,

-> grade varchar(100) default 'e1',

-> gross int check(gross>500));

Query OK, 0 rows affected (0.32 sec)

mysql> desc employee;

+-------+--------------+------+-----+---------+-----
--+
| Field | Type | Null | Key | Default |
Extra |

+-------+--------------+------+-----+---------+-----
--+

| ecode | int(11) | NO | PRI | NULL |


|

| sex | varchar(100) | NO | | NULL |


|

| grade | varchar(100) | YES | | e1 |


|

| gross | int(11) | YES | | NULL |


|

+-------+--------------+------+-----+---------+-----
--+

4 rows in set (0.00 sec)

You might also like