Followers

MySql- Working with tables

  Working with tables Show all tables in a current database. SHOW TABLES ; Code language: SQL (Structured Query Language) ( sql ) Create ...

 

Working with tables

Show all tables in a current database.

SHOW TABLES;
Code language: SQL (Structured Query Language) (sql)

Create a new table

CREATE TABLE [IF NOT EXISTS] table_name( column_list );
Code language: SQL (Structured Query Language) (sql)

Example: Create a table student.

            create table student(Id int, name varchar(30),marks int);

Example : To see all the fields of student table;

     desc student

Add a new column into a table:

ALTER TABLE table ADD [COLUMN] column_name;
Code language: SQL (Structured Query Language) (sql)

Example: To add a new column Grade varchar(2) in student table.

         Alter table student add Grade varchar(2);

         desc student;            


Drop a column from a table:

ALTER TABLE table_name DROP [COLUMN] column_name;
Code language: SQL (Structured Query Language) (sql)

Example: to Delete Grade column

        Alter table student drop Grade ;

        desc student;

Add index with a secific name to a table on a column:

ALTER TABLE table ADD INDEX [name](column, ...);
Code language: SQL (Structured Query Language) (sql)

Add primary key into a table:

ALTER TABLE table_name ADD PRIMARY KEY (column_name,...);

Example: To create teachers table and add primary key to the Id column

    create table teachers( id int Primary key, name varchar(30));

    desc teachers;

Remove the primary key of a table:

ALTER TABLE table_name DROP PRIMARY KEY;

Example 

   Alter table teachers drop Primary key;

  desc teachers;

Example Again add the Primary key to the teachers table;

   Alter table teachers Add Primary key(Id);

   desc teachers;

Drop a table:

DROP TABLE [IF EXISTS] table_name;
Code language: SQL (Structured Query Language) (sql)

Example:- Delete teachers table

    Drop table teachers;

Show the columns of a table:

DESCRIBE table_name;
Code language: SQL (Structured Query Language) (sql)

Show the information of a column in a table:

DESCRIBE table_name column_name;

COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: MySql- Working with tables
MySql- Working with tables
DevOpsWorld
https://www.devopsworld.co.in/2022/04/mysql-working-with-tables.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/04/mysql-working-with-tables.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content