Table operations-Create Table-delete table-Modify Table Name-Modify column name and data type-delete/Add primary key-Add a column at the end of the table-View table structure

Source: Internet
Author: User
Use dB;


-- List all tables in the current database
Show tables;
Show tables like's % ';


Create Table Name
(
Column name type modification constraints,
Sid int (3) unsigned zerofill primary key auto_increment
Sgender Enum ('male', 'female ', 'confidential') default 'male'
) Engine = MyISAM default charset = utf8;




-- Create a table
Create Table if not exists s
(
Sid int (3) unsigned zerofill primary key auto_increment,
Sname varchar (5) not null,
Sgender Enum ('male', 'female ', 'confidential') default 'male'
) Engine = MyISAM default charset = utf8;


-- Quickly copy the table structure and create a new table
Create Table if not exists YY like student;


Create Table if not exists XX select * from student;




Select * from student;
Select * from YY;
Insert into XX select * from XX;
Insert into student select * from student;


Select * from XX;




Desc YY;




Insert into S values (30, 'zhang san', 'A ');
Insert into S (sname) values ('Li Yong ');


Desc S;


Select * from s where sgender = '';


-- Delete a table
Drop table if exists st;


-- Delete a batch of tables
Drop table if exists's ', 'XX', 'cc ';


-- Modify the table name
Rename table student to bbs_student;
Alter table bbs_student rename student;
Alter table bbs_student Rename to student;


-- Modify the column name and Data Type
Alter table student change Sid SnO int unsigned;


-- Delete the primary key of a table
Alter table student drop primary key;


-- Add a primary key to a table
Alter table student add constraint PK primary key (SNO );


Desc student;


-- Add a column at the end of the table
Alter table student add column sscore tinyint unsigned;
Alter table student add column sscore tinyint unsigned first;
Alter table student add column sscore tinyint unsigned after sname;




-- Delete a column
Alter table student drop column sscore;







-- View table structure
Desc student;

Table operations-Create Table-delete table-Modify Table Name-Modify column name and data type-delete/Add primary key-Add a column at the end of the table-View table structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.