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

Dbms Table

The document shows SQL commands used to create a database and table, insert data, and run queries in MySQL. Several rows are inserted into a table called tablename with fields like sid, sname, city, salary etc. and a final select statement retrieves all rows from the table.

Uploaded by

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

Dbms Table

The document shows SQL commands used to create a database and table, insert data, and run queries in MySQL. Several rows are inserted into a table called tablename with fields like sid, sname, city, salary etc. and a final select statement retrieves all rows from the table.

Uploaded by

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

Enter password: ***********

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 15
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database company;


Query OK, 1 row affected (0.01 sec)

mysql> use company;


Database changed
mysql> create table(sid varchar(5) primary key, sname varchar(10) not null, city
varchar(15) not null, salary int(5) not null, product varchar(20) not null,
typetoget int(4) not null);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '(sid
varchar(5) primary key, sname varchar(10) not null, city varchar(15) not nu' at
line 1
mysql> create table tablename(sid varchar(5) primary key, sname varchar(10) not
null, city varchar(15) not null, salary int(5) not null, product varchar(20) not
null, typetoget int(4) not null);
Query OK, 0 rows affected, 2 warnings (0.04 sec)

mysql> desc tablename;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| sid | varchar(5) | NO | PRI | NULL | |
| sname | varchar(10) | NO | | NULL | |
| city | varchar(15) | NO | | NULL | |
| salary | int | NO | | NULL | |
| product | varchar(20) | NO | | NULL | |
| typetoget | int | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

mysql> insert into tablename values('S01', 'aaryan', 'kanpur', -1, 'joystick', 1);
Query OK, 1 row affected (0.01 sec)

mysql> desc tablename;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| sid | varchar(5) | NO | PRI | NULL | |
| sname | varchar(10) | NO | | NULL | |
| city | varchar(15) | NO | | NULL | |
| salary | int | NO | | NULL | |
| product | varchar(20) | NO | | NULL | |
| typetoget | int | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> insert into tablename values('S01', 'aaryan', 'kanpur', -1, 'joystick', 1)
-> insert into tablename values('S02', 'jay', 'balia', 1000, 'scanner', 1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'insert
into tablename values('S02', 'jay', 'balia', 1000, 'scanner', 1)' at line 2
mysql> desc tablename;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| sid | varchar(5) | NO | PRI | NULL | |
| sname | varchar(10) | NO | | NULL | |
| city | varchar(15) | NO | | NULL | |
| salary | int | NO | | NULL | |
| product | varchar(20) | NO | | NULL | |
| typetoget | int | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into tablename values('So1', 'jay', 'balia', 1000, 'scanner', 1);
Query OK, 1 row affected (0.01 sec)

mysql> insert into tablename values('S02', 'aryan', 'kanpur', 2000, 'joystick', 1);
Query OK, 1 row affected (0.01 sec)

mysql> insert into tablename values('So3', 'chirag', 'delhi', 10000, 'computer',


1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into tablename values('So4', 'dhruv', 'deoria', 135000, 'keyboard',


1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into tablename values('S03', 'prakhar', 'prayagraj', 50000,


'controller', 1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from tablename;


+-----+---------+-----------+--------+------------+-----------+
| sid | sname | city | salary | product | typetoget |
+-----+---------+-----------+--------+------------+-----------+
| S01 | aaryan | kanpur | -1 | joystick | 1 |
| S02 | aryan | kanpur | 2000 | joystick | 1 |
| S03 | prakhar | prayagraj | 50000 | controller | 1 |
| So1 | jay | balia | 1000 | scanner | 1 |
| So3 | chirag | delhi | 10000 | computer | 1 |
| So4 | dhruv | deoria | 135000 | keyboard | 1 |
+-----+---------+-----------+--------+------------+-----------+
6 rows in set (0.00 sec)

You might also like