The document discusses various SQL ALTER TABLE and CREATE TABLE statements to add, modify, and drop columns, constraints, and keys for different table structures. It shows how to add, modify, and drop columns, unique constraints, primary keys, and drop tables using ALTER TABLE and CREATE TABLE statements.
The document discusses various SQL ALTER TABLE and CREATE TABLE statements to add, modify, and drop columns, constraints, and keys for different table structures. It shows how to add, modify, and drop columns, unique constraints, primary keys, and drop tables using ALTER TABLE and CREATE TABLE statements.
The document discusses various SQL ALTER TABLE and CREATE TABLE statements to add, modify, and drop columns, constraints, and keys for different table structures. It shows how to add, modify, and drop columns, unique constraints, primary keys, and drop tables using ALTER TABLE and CREATE TABLE statements.
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
ALTER TABLE Persons MODIFY COLUMN PersonID varchar(20);
insert into Persons(PersonID,LastName ) values('a3','bhuvan');
select * from Persons;
CREATE TABLE table_name (
column1 datatype constraint, column2 datatype constraint, column3 datatype constraint, .... ); -- not null CREATE TABLE Persons1 ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int ); insert into Persons1(ID,LastName) values(2,'bhuvan');
select * from Persons1;
ALTER TABLE Persons MODIFY Age int NOT NULL;
-- unique
CREATE TABLE Persons4 (
ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, CONSTRAINT unq_tab_id UNIQUE(id) ); describe Persons4;
ALTER TABLE Persons ADD UNIQUE (ID);
ALTER TABLE Persons4 DROP CONSTRAINT unq_tab_id;
-- primary key
CREATE TABLE Persons2 (
ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, PRIMARY KEY (ID) );
ALTER TABLE Persons ADD PRIMARY KEY (ID);
ALTER TABLE Persons2 DROP PRIMARY KEY ;
ALTER TABLE Persons ADD CONSTRAINT PK_Person PRIMARY KEY (ID,LastName);