1. Create the table customers in the database Market
1. Create a database
mysql> create database Market;
mysql> use Market;
2. Create a data table
mysql> create table customers(
- > c_num int ( 11 ) primary key auto_increment ,
- > c_name varchar ( 50 ) ,
- > c_contact varchar ( 50 ) ,
- > c_city varchar ( 50 ) ,
- > c_birth datetime not null
- > ) ;
3. Insert the c_contact field after the c_birth field
mysql> alter table customers modify column c_contact varchar ( 50 ) after c_birth;
4. Change the data type of the c_name field to varchar(70)
mysql> alter table customers modify c_name varchar ( 70 ) ;
5. Change the c_contact field to c_phone
mysql> alter table customers change c_contact c_phone varchar ( 50 ) ;
6. Add c_gender field, the data type is char(1)
mysql> alter table customers add c_gender char ( 1 ) ;
7. Change the table name to customers_info
mysql> rename table customers to customers_info;
8. Delete the field c_city
mysql> alter table customers_info drop c_city;
9. Modify the storage engine of the data table to MyISAM.
mysql> alter table customers_info engine = MyISAM;
mysql> SHOW TABLE STATUS LIKE 'customers_info' ;
2. Create table orders in Market
1. Create a data table
mysql> create table orders(
- > o_name int ( 11 ) primary key auto_increment ,
- > o_date date ,
- > c_id int ( 50 )
- > ) ;
mysql> alter table customers_info engine = InnoDB ;
mysql> alter table orders add foreign key ( c_id) references customers_info( c_num) ;
2. Delete the foreign key constraint on the orders table, and then delete the table customers_info.
mysql> show create table orders;
mysql> alter table orders drop foreign key orders_ibfk_1;
mysql> drop table customers_info;
3. Database Team
1. Create a new account, the user name is account1, the user connects to the database through the local host, and the password is oldpwd1. Authorize the user to SELECT and INSERT the player table in the Team database, and authorize the user to UPDATE the info field of the player table.
mysql> create user 'account1' @'localhost' identified by 'Oldpwd1.' ;
mysql> grant select , insert on Team. player to account1@localhost ;
mysql> grant update ( info) on Team. player to account1@localhost ;
mysql> FLUSH PRIVILEGES ;
2. Create an SQL statement to change the password of the account1 user to newpwd2.
mysql> alter user account1@localhost identified by 'Newpwd2.' ;
3. Create an SQL statement and use FLUSH PRIVILEGES to reload the privilege table.
mysql> FLUSH PRIVILEGES ;
4. Create an SQL statement to view the permissions authorized to the account1 user.
mysql> show grants for account1@localhost ;
5. Create an SQL statement to withdraw the authority of the account1 user.
mysql> revoke all privileges on * . * from account1@localhost ;
6. Create an SQL statement to delete the account information of the account1 user from the system.
mysql> drop user account1@localhost ;