0% found this document useful (0 votes)
14 views1 page

Alter Commands

The document contains a series of MySQL commands for altering database tables, specifically adding and changing columns in the 'accounts' and 'branch' tables. The 'accounts' table was modified to include a 'last_name' column and change the 'name' column to 'first_name'. The document also includes the results of the 'desc' command showing the updated structure of both tables.
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)
14 views1 page

Alter Commands

The document contains a series of MySQL commands for altering database tables, specifically adding and changing columns in the 'accounts' and 'branch' tables. The 'accounts' table was modified to include a 'last_name' column and change the 'name' column to 'first_name'. The document also includes the results of the 'desc' command showing the updated structure of both tables.
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/ 1

Alter commands

mysql> alter table accounts add last_name varchar(30) not null after name;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table branch add ifsc varchar(15) not null;


Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc branch


->
->
-> ^C
mysql> desc branch;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| branch_id | int | NO | PRI | NULL | |
| branch_name | varchar(30) | NO | | NULL | |
| branch_ph | bigint | NO | UNI | NULL | |
| ifsc | varchar(15) | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> desc accounts;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Acc_No | bigint | NO | PRI | NULL | |
| name | varchar(30) | NO | UNI | NULL | |
| last_name | varchar(30) | NO | | NULL | |
| phone | bigint | NO | UNI | NULL | |
| mail | varchar(40) | NO | UNI | NULL | |
| branch_id | int | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> alter table accounts name first_name varchar(30) not null unique;
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 'name
first_name varchar(30) not null unique' at line 1
mysql> alter table accounts change name first_name varchar(30) not null unique;
Query OK, 0 rows affected, 1 warning (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 1

mysql> desc accounts;


+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| Acc_No | bigint | NO | PRI | NULL | |
| first_name | varchar(30) | NO | UNI | NULL | |
| last_name | varchar(30) | NO | | NULL | |
| phone | bigint | NO | UNI | NULL | |
| mail | varchar(40) | NO | UNI | NULL | |
| branch_id | int | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

You might also like