Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Database Management System

Similar presentations


Presentation on theme: "Advanced Database Management System"— Presentation transcript:

1 Advanced Database Management System
Lab no. 12

2 Outline SQL Commands (for MySQL) Alter Command phpMyAdmin (DB backup)

3 Alter table statement Changing a table name Adding Columns
alter table table_name rename new_table_name; Adding Columns alter table table_name add column column_name column_attributes; Dropping Columns alter table table_name drop column column_name;

4 Alter table statement You can add indexes using the index, unique, and primary key commands in the same way you would use them in the create statement: Adding index alter table my_table add index index_name (column_name1); Dropping Index alter table my_table drop index index_name; Adding unique index constraint alter table my_table add unique index_name(column_name); Note that unique index cannot be created on a column with duplicate values Adding Unique constraint on a column alter table my_table add unique(column_name);

5 Alter table statement Dropping primary key Adding primary key
alter table my_table add primary key(my_column); Dropping primary key alter table my_table drop primary key;

6 Alter table statement Dropping foreign key Adding foreign key
alter table my_table add foreign key (my_column) references other_table(col); Dropping foreign key alter table my_table drop foriegn key; Note: Other option to add foreign key from PHPMyAdmin is shown in next slide You will have to create an index on the foreign key column then select the option shown in next slide.

7

8

9 Alter cont’d Changing column definitions
It is possible to change a column’s name or attributes with either the change or modify command. To change a column’s name you must also redefine the column’s attributes. The following will work: alter table my_table change old_col new_col int not null; To change a column’s characteristics/attributes, do the following: alter table my_table modify col_name varchar(50);

10 For further reference on ALTER

11 Show statement cont’d show columns show index show table status
Syntax: show columns from table_name; show index Syntax: show index from table_name; show table status Syntax: Show table status like ‘table_name’;

12 The Show statement Show Database: On mySql console write…
mysql> show databases; Show Tables: On MySql console write… mysql> Use guestbook; mysql> show tables; Example: mysql> use guestbook; Database changed | Tables_in_guestbook | | guestbook | | guestbook | | my_table | 3 rows in set (0.11 sec) mysql>

13 Example mysql> show table status like 'guestbook'
*************************** 1. row *************************** Name: guestbook Engine: InnoDB Version: 10 Row_format: Compact Rows: 0 Avg_row_length: 0 Data_length: 16384 Max_data_length: 0 Index_length: 0 Data_free: 0 Auto_increment: NULL Create_time: :38:12 Update_time: NULL Check_time: NULL Collation: latin1_swedish_ci Checksum: NULL Create_options: Comment: InnoDB free: 4096 kB 1 row in set (0.02 sec) mysql>_

14 Show cont’d Show create table: Syntax: show create table guestbook
mysql> show create table guestbook *************************** 1. row *************************** Table: guestbook Create Table: CREATE TABLE `guestbook` ( `name` varchar(40) default NULL, `location` varchar(40) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) mysql>

15 Taking Database Backup


Download ppt "Advanced Database Management System"

Similar presentations


Ads by Google