1.

MySQL Table commands(DDL)

Answer»
COMMANDMEANINGSYNTAX
show tablesShows all tables within the current database. >SHOW TABLES;
create tableCreates a new table in the current database. >CREATE TABLE TABLENAME (
   COLUMN1 DATATYPE,
   COLUMN2 DATATYPE,
   COLUMN3 DATATYPE,
  ....
CONSTRAINTS ....
);
alter table (add column)Adds a new column to an existing table.  >ALTER TABLE TABLENAME ADD COLUMNNAME DATATYPE;
alter table (drop column)Deletes a column from an existing table. >ALTER TABLE TABLENAME DROP COLUMN COLUMNNAME;
alter table (alter column)Alters an existing column in an already existing table. >ALTER TABLE TABLENAME
ALTER COLUMN COLUMNNAME DATATYPE;
alter table(add primary key)Alters or adds primary key to an existing table. >ALTER TABLE TABLENAME
ADD PRIMARY KEY (COLUMNNAME,...);
alter table(drop primary key)Drops an existing primary key in a table. >ALTER TABLE TABLENAME
DROP PRIMARY KEY;
alter table(add foreign key)Creates a foreign key on an existing table. >ALTER TABLE TABLENAME1 ADD FOREIGN KEY (COLUMN1) REFERENCES TABLENAME2(COLUMN2);
alter table(drop foreign key)Deletes an existing foreign key in an already existing table. > ALTER TABLE TABLENAME DROP FOREIGN KEY FOREIGNKEY_NAME;
rename tableChanges the name of an existing table. >RENAME TABLE OLD_TABLENAME TO NEW_TABLENAME;
drop tableDeletes the entire table along with its definition. >DROP TABLE TABLE_NAME;
truncate tableRemove all records in a MySQL table. >TRUNCATE TABLE TABLENAME;
describe tableDisplays all the columns of an existing table. >DESCRIBE TABLE_NAME;
describe table columnDisplays all the values stored in a particular column. >DESCRIBE TABLE_NAME COLUMN_NAME;



Discussion

No Comment Found