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

Create Database School

asfas

Uploaded by

chitratanwar45b
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)
22 views

Create Database School

asfas

Uploaded by

chitratanwar45b
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

create database school ;

Query OK, 1 row affected (0.00 sec)

mysql> use school ;


Database changed
mysql> create table GAURDIAN
-> (
-> GUID char(12) PRIMARY KEY ,
-> GName varchar(20) NOT NULL,
-> GPhone char (10) UNIQUE,
-> GAdress varchar(25) NOT NULL
-> );
Query OK, 0 rows affected (0.08 sec)

mysql> desc guardian ;


ERROR 1146 (42S02): Table 'school.guardian' doesn't exist
mysql> desc school.gaurdian ;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | PRI | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> alter table gaurdian


-> add(GIncome float );
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc school.gaurdian ;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | PRI | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
| GIncome | float | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table gaurdian


-> add(GEmail varchar(25), GPinCode int );
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc school.gaurdian ;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | PRI | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
| GIncome | float | YES | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> alter table gaurdian


-> drop(GIncome);
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 '(GIncome)' at line 2
mysql> alter table gaurdian
-> drop(GIncome float);
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 '(GIncome float)' at line 2
mysql> alter table gaurdian
-> del(GIncome );
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 'del(GIncome )' at line 2
mysql> alter table gaurdian
-> drop \GIncome;
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 '' at line 2
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 'Income' at line 1
mysql> alter table gaurdian
-> drop GIncome ;
Query OK, 0 rows affected (0.43 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc school.gaurdian ;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | PRI | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)
mysql> alter table gaurdian
-> drop constraint GUID;
ERROR 3940 (HY000): Constraint 'GUID' does not exist.
mysql> alter table gaurdian
-> drop constraint primary key;
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 'primary key' at line 2
mysql> alter table gaurdian
-> drop primary key ;
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc school.gaurdian;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> desc gaurdian ;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(25) | NO | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> alter table gaurdian


-> modify(GAdress varchar(30) );
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 '(GAdress varchar(30) )' at line 2
mysql> alter table gaurdian
-> modify GAdress varchar(30) ;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> create table STUDENT


-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) Foreign Key
-> );
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 'Foreign Key
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID
-> 0
-> );
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 '0
)' at line 7
mysql> create table STUDENT
-> (
-> RollNumber int ,
->
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID
-> 0
-> );
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 '0
)' at line 8
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID
-> 0
-> );
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 '0
)' at line 7
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> 0
-> );
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 '0
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID char(12)
-> );
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 'char(12)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID
-> );
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 ')' at line 7
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12)
-> foreign key GUID
-> );
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 'foreign key GUID
)' at line 7
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) reference guardian(GUID)
-> );
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 'reference guardian(GUID)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) , reference guardian(GUID)
-> );
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 'guardian(GUID)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) reference gaurdian(GUID)
-> );
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 'reference gaurdian(GUID)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) reference gaurdian(GUID)
-> );
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 'reference gaurdian(GUID)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12) references gaurdian(GUID)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> desc student;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| RollNumber | int | YES | | NULL | |
| SName | varchar(20) | YES | | NULL | |
| SDateOfBirth | date | NO | | NULL | |
| GUID | char(12) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> del student ;


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 'del student' at line 1
mysql> delete student ;
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 '' at line 1
mysql> drop student ;
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 'student' at line 1
mysql>
mysql> delete table student ;
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 'table student' at line 1
mysql> drop table student ;
Query OK, 0 rows affected (0.01 sec)

mysql> desc student ;


ERROR 1146 (42S02): Table 'school.student' doesn't exist
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> foreign key GUID char(12) references gaurdian(GUID)
-> );
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 'char(12) references gaurdian(GUID)
)' at line 6
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12)
-> foreign key GUID references gaurdian(guid)
-> );
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 'foreign key GUID references gaurdian(guid)
)' at line 7
mysql> create table STUDENT
-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date NOT NULL,
-> GUID char(12)
-> foreign key (GUID) references gaurdian(guid)
-> );
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 'foreign key (GUID) references gaurdian(guid)
)' at line 7
mysql> create table STUDENT
-> -> (
-> -> RollNumber int ,
-> -> SName varchar(20),
-> -> SDateOfBirth date NOT NULL,
-> -> foreign key GUID char(12) references gaurdian(GUID)
-> -> );
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 '-> (
-> RollNumber int ,
-> SName varchar(20),
-> SDateOfBirth date ' at line 2
mysql> create table STUDENT
-> -> (
-> -> RollNumber int ,
-> -> SName varchar(20),
-> -> SDateOfBirth date NOT NULL,
-> -> foreign key GUID char(12) references gaurdian(GUID)

mysql> show data bases


-> ;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id: 13
Current database: *** NONE ***

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 'data bases' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| s2 |
| school |
| sys |
+--------------------+
6 rows in set (0.01 sec)

mysql> use school ;


Database changed
mysql> create table STUDENT
-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> FOREIGN KEY(GUID) REFERENCES gaurdian(GUID)
-> );
ERROR 1072 (42000): Key column 'GUID' doesn't exist in table
mysql>
mysql> desc gaurdian;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(30) | YES | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> create table STUDENT


-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> FOREIGN KEY(GUID) REFERENCES gaurdian(GUID)
-> );
ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing
index for constraint 'student_ibfk_1' in the referenced table
'gaurdian'
mysql> create table STUDENT
-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> FOREIGN KEY(GUID) REFERENCES guardian(GUID)
-> );
ERROR 1824 (HY000): Failed to open the referenced table 'guardian'
mysql> create table STUDENT
-> (
-> RollNumber INT,
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> l
-> ;
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 '' at line 6
mysql> create table STUDENT
-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> FOREIGN KEy GUID REFERENCES gaurdian(GUID)
-> );
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 'REFERENCES gaurdian(GUID)
)' at line 7
mysql> create table STUDENT
-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> CONSTRAINT student_ibfk_1 FOREIGN KEY (GUID) REFERENCES
gaurdian(GUID)
-> );
ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing
index for constraint 'student_ibfk_1' in the referenced table
'gaurdian'
mysql> desc gaurdian;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(30) | YES | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> alter table gaurdian


-> modify column GUID char(12) PRIMARY KEY ;
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> create table STUDENT


->
-> (
-> RollNumber INT,
-> SName varchar(20),
-> SDateOfBirth DATE NOT NULL,
-> GUID char(12),
-> FOREIGN KEY (GUID) REFERENCES gaurdian(GUID)
-> );
Query OK, 0 rows affected (0.07 sec)

mysql> desc gaurdian ;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| GUID | char(12) | NO | PRI | NULL | |
| GName | varchar(20) | NO | | NULL | |
| GPhone | char(10) | YES | UNI | NULL | |
| GAdress | varchar(30) | YES | | NULL | |
| GEmail | varchar(25) | YES | | NULL | |
| GPinCode | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> desc student ;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| RollNumber | int | YES | | NULL | |
| SName | varchar(20) | YES | | NULL | |
| SDateOfBirth | date | NO | | NULL | |
| GUID | char(12) | YES | MUL | NULL | |
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

You might also like