uNIT3(LABORAOTRY) Flashcards
You can alter an existing table by adding one or more columns. In the following example, you add the column named p_salecode to the tbl_product table.
alter table tbl_product
add p_salecode char(1)
Altering/Changing a Column
If we want to change the size of column pt_name in table tbl_part from varchar(500) to varchar(250)
// SQL Server
alter table tbl_part
alter column pt_name varchar(250);
// MySQL
alter table tbl_part
modify column pt_name varchar(250);
Dropping a Column
Suppose that you want to delete the V_ORDER attribute from the VENDOR table.
(SQL Server and MySQL)
alter table tbl_vendor
drop column v_order
Adding Primary Key and Foreign Keys
if the tbl_part table’s foreign key has not yet been designated, it can be designated by:
(SQL Server and MySQL)
alter table tbl_part
add foreign key (v_code) references tbl_vendor (v_code);
Adding Primary Key and Foreign Keys
if neither the tbl_line table’s primary key nor its foreign key has been designated, you can incorporate both changes at once, using:
(SQL Server and MySQL)
alter table tbl_line
add primary key (inv_number, line_number);
Deleting Table from Database, you can delete the PART table you just created with:
Syntax is : DROP TABLE tableName
(SQL Server and MySQL)
drop table tbl_part