0% found this document useful (0 votes)
24 views3 pages

Mysqlday 2

The document shows SQL commands used to create tables, insert data, and query tables in a MySQL database. Several tables are created - author, publisher, book, and rack. Data is inserted into these tables and select queries are run to view the data.

Uploaded by

sunilhingole6
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)
24 views3 pages

Mysqlday 2

The document shows SQL commands used to create tables, insert data, and query tables in a MySQL database. Several tables are created - author, publisher, book, and rack. Data is inserted into these tables and select queries are run to view the data.

Uploaded by

sunilhingole6
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/ 3

Day 2;

Microsoft Windows [Version 10.0.22621.2361]


(c) Microsoft Corporation. All rights reserved.

C:\Users\vspaw>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> use dbda;


Database changed
mysql> CREATE TABLE author(
-> authorid int(10),PRIMARY KEY,
-> AFname varchar(20)NOT NULL,
-> nationality,
-> AFname varchar(20)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 ',
AFname varchar(20)NOT NULL,
nationality,
AFname varchar(20)NOT NULL,

)' at line 2
mysql> CREATE TABLE author(
-> authorid int(10)PRIMARY KEY,
-> AFname varchar(20)NOT NULL,
-> nationality varchar(40),
-> gender enum('M','F')
-> );
ERROR 1050 (42S01): Table 'author' already exists
mysql> describe author;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| authorid | varchar(10) | NO | PRI | NULL | |
| AFname | varchar(30) | NO | | NULL | |
| nationality | varchar(40) | YES | | NULL | |
| gender | enum('M','F') | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> describe rack;


+---------------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-----------------------+------+-----+---------+-------+
| rackid | varchar(10) | NO | PRI | NULL | |
| rackcapacity | int | YES | | NULL | |
| rackdirection | enum('N','S','E','W') | YES | | NULL | |
+---------------+-----------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe publisher;


+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| publisherid | varchar(10) | NO | PRI | NULL | |
| publishername | varchar(20) | YES | UNI | NULL | |
| country | varchar(30) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe book;


+---------------+----------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------+------+-----+---------+-------+
| bookid | varchar(10) | NO | PRI | NULL | |
| bookname | varchar(20) | YES | UNI | NULL | |
| authorid | varchar(10) | YES | MUL | NULL | |
| category | varchar(20) | YES | | NULL | |
| cost | int | YES | | NULL | |
| pages | int | YES | | NULL | |
| rackid | varchar(10) | YES | MUL | NULL | |
| bookstatus | enum('A','NA') | YES | | NULL | |
| publisherid | varchar(10) | YES | MUL | NULL | |
| bookissuedate | date | YES | | NULL | |
| bookissuetime | time | YES | | NULL | |
+---------------+----------------+------+-----+---------+-------+
11 rows in set (0.00 sec)

mysql> INSERT INTO rack VALUES('R001',210,'N');


ERROR 1062 (23000): Duplicate entry 'R001' for key 'rack.PRIMARY'
mysql> select * from rack;
+--------+--------------+---------------+
| rackid | rackcapacity | rackdirection |
+--------+--------------+---------------+
| R001 | 100 | N |
+--------+--------------+---------------+
1 row in set (0.00 sec)

mysql> INSERT INTO author('A001','chetan bhagat','bharat','M');


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
''A001','chetan bhagat','bharat','M')' at line 1
mysql> INSERT INTO author VALUES('A001','chetan bhagat','bharat','M');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO publisher VALUES('P001','Harper collin','USA');


Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO book VALUES('B001','2


states','A001','friction',2500,235,'R001','A','P001','2023/10/25','10:25');
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> select * from book;


+--------+----------+----------+----------+------+-------+--------+------------
+-------------+---------------+---------------+
| bookid | bookname | authorid | category | cost | pages | rackid | bookstatus |
publisherid | bookissuedate | bookissuetime |
+--------+----------+----------+----------+------+-------+--------+------------
+-------------+---------------+---------------+
| B001 | 2 states | A001 | friction | 2500 | 235 | R001 | A |
P001 | 2023-10-25 | 10:25:00 |
+--------+----------+----------+----------+------+-------+--------+------------
+-------------+---------------+---------------+
1 row in set (0.00 sec)

mysql> select * from author;


+----------+---------------+-------------+--------+
| authorid | AFname | nationality | gender |
+----------+---------------+-------------+--------+
| A001 | chetan bhagat | bharat | M |
+----------+---------------+-------------+--------+
1 row in set (0.00 sec)

mysql> select * from publisher;


+-------------+---------------+---------+
| publisherid | publishername | country |
+-------------+---------------+---------+
| P001 | Harper collin | USA |
+-------------+---------------+---------+
1 row in set (0.00 sec)

mysql> select * from rack;


+--------+--------------+---------------+
| rackid | rackcapacity | rackdirection |
+--------+--------------+---------------+
| R001 | 100 | N |
+--------+--------------+---------------+
1 row in set (0.00 sec)

mysql

You might also like