The document shows the steps to create a MySQL database called Batch7pm and a table called Employee within it. It inserts some sample records into the Employee table and runs some queries to view the data.
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 ratings0% found this document useful (0 votes)
18 views
My SQL First Class
The document shows the steps to create a MySQL database called Batch7pm and a table called Employee within it. It inserts some sample records into the Employee table and runs some queries to view the data.
+---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | empid | int | NO | PRI | NULL | | | empname | varchar(40) | YES | | NULL | | | region | varchar(40) | YES | | NULL | | | salary | int | YES | | NULL | | | deptid | int | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 5 rows in set (0.01 sec)
mysql> select * from Employee;
Empty set (0.00 sec)
mysql> desc emp;
ERROR 1146 (42S02): Table 'batch7pm.emp' doesn't exist mysql> create table Employee(empid int primary key,empname varchar,region varchar(40),salary int, deptid 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 ',region varchar(40),salary int, deptid int)' at line 1 mysql> desc employee; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | empid | int | NO | PRI | NULL | | | empname | varchar(40) | YES | | NULL | | | region | varchar(40) | YES | | NULL | | | salary | int | YES | | NULL | | | deptid | int | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 5 rows in set (0.01 sec)
mysql> insert into employee values(101,"Rohit","West",97000,1);
Query OK, 1 row affected (0.01 sec)
mysql> select * from Employee;
+-------+---------+--------+--------+--------+ | empid | empname | region | salary | deptid | +-------+---------+--------+--------+--------+ | 101 | Rohit | West | 97000 | 1 | +-------+---------+--------+--------+--------+ 1 row in set (0.00 sec)
mysql> insert into employee values(101,"Sonia","West",97000,1);
ERROR 1062 (23000): Duplicate entry '101' for key 'employee.PRIMARY' mysql> insert into employee values(NUll,"Sonia","West",97000,1); ERROR 1048 (23000): Column 'empid' cannot be null mysql> insert into employee values(102,"Rohit","East",77000,2); Query OK, 1 row affected (0.01 sec)
mysql> select * from Employee;
+-------+---------+--------+--------+--------+ | empid | empname | region | salary | deptid | +-------+---------+--------+--------+--------+ | 101 | Rohit | West | 97000 | 1 | | 102 | Rohit | East | 77000 | 2 | +-------+---------+--------+--------+--------+ 2 rows in set (0.00 sec)