Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
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 university;
Query OK, 1 row affected (0.03 sec)
mysql> create table department(id int,name varchar(30));
ERROR 1046 (3D000): No database selected
mysql> use university;
Database changed
mysql> create table department(id int,name varchar(30));
Query OK, 0 rows affected (0.33 sec)
mysql> create table student(id int,code varchar(8),fname varchar(30),lname varch
ar(30),phone int,email varchar(30),int depid);
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 'int d
epid)' at line 1
mysql> create table student(id int,code varchar(8),fname varchar(30),lname varch
ar(30),phone int,email varchar(30),depid int);
Query OK, 0 rows affected (0.35 sec)
mysql> show tables;
+----------------------+
| Tables_in_university |
+----------------------+
| department |
| student |
+----------------------+
2 rows in set (0.00 sec)
mysql> alter table department add primary key(id);
Query OK, 0 rows affected (0.65 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> create table lesson(id int,name varchar(30));
Query OK, 0 rows affected (0.28 sec)
mysql> alter table lesson add primary key(id);
Query OK, 0 rows affected (0.66 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table student add primary key(id);
Query OK, 0 rows affected (0.67 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table student add foreign key(depid) references department(id);
Query OK, 0 rows affected (0.74 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table lesson add foreign key(depid) references department(id);
ERROR 1072 (42000): Key column 'depid' doesn't exist in table
mysql> alter table lesson alter column credit int;
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 'int'
at line 1
mysql> alter table lesson add credit int;
Query OK, 0 rows affected (0.63 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table lesson add depid int;
Query OK, 0 rows affected (0.47 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table lesson add foreign key(depid) references department(id);
Query OK, 0 rows affected (0.68 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into department values(1,"Computer science");
Query OK, 1 row affected (0.07 sec)
mysql> insert into department values(2,"Information Technology");
Query OK, 1 row affected (0.05 sec)
mysql> insert into department values(3,"Multimedia");
Query OK, 1 row affected (0.04 sec)
mysql> insert into department values(4,"Internet Business");
Query OK, 1 row affected (0.06 sec)
mysql> insert into department values(5,"Electronic Engineering");
Query OK, 1 row affected (0.06 sec)
mysql> insert into department values(6,"Medical Engineering");
Query OK, 1 row affected (0.05 sec)
mysql> insert into student values(1,IC11D001,"bat","dorj",99898989,"bat@yahoo.co
m",1);
ERROR 1054 (42S22): Unknown column 'IC11D001' in 'field list'
mysql> insert into student values(1,'IC11D001','bat','dorj',99898989,'bat@yahoo.
com',1);
Query OK, 1 row affected (0.07 sec)
mysql> insert into student values(1,'IC11D001','bat','dorj',99898989,'bat@yahoo.
com',1);
No comments:
Post a Comment