Basic Use Of My SQL workbench and basic SQL statements

Source: Internet
Author: User
Guidance:

This articleArticleIt will teach you how to use my SQL workbench 5.2 to perform basic database operations (create databases, tables, etc)

Preface

MySQL is a product of Oracle, so it is quite similar to Oracle in some places. For example, the concept of "server instance" was originally changed from sqlserver to Oracle, at first, I didn't understand what this server instance was. Because in SQL Server, there was only one server. After login, it was the operation of the database. Basically, a project corresponds to a database.

However, some projects are huge and many databases need to be created. Multiple Data belongs to the same project. Then, a server instance can be created, you can create the required database under this instance. After a server instance is created, a port will be allocated to the instance (this is necessary because it is already a server) the corresponding services will also be added to the Windows System Service list. At this time, you should have a better understanding of what is a server instance. Basically: A project corresponds to a server instance.

The creation of server instances has not been thoroughly studied, so I will leave it empty first, and I will add it later. I chose to create the default server instance during installation, now let's use it to create a database. Double-click the server instance to be connected and enter the password. Then, select database> query database and select OK, the tree on the left of a new page is the list of all databases under the server instance. The middle part is the place where SQL statements are executed. The executed SQL statements (click the lightning icon) Create a database, in the tree structure on the left, right-click an item and select refresh all. The new database comes out. Note: My database files are stored in E: \ programdata \ mysql server 5.5 \ data drive letter corresponding to a database is a folder to create a data table
Use Ceshi; Create Table student (stuid int primary key auto_increment, stuname varchar (40) not null );

In this way, a studeng table is created, and auto_increment indicates the auto-incrementing column to insert data.

 
Insert into student (stuname) values ('hangsan'); insert into student value (2, 'lisi'); insert into student value (10, 'hangzhou '); insert into student (stuname) value ('maliu ');

In this way, four data records are inserted and the insertion method of the auto-increment column is tested,

If the insert auto-increment column is not specified in the statement, the value of the insert auto-increment column starts from 1 by default, and the value of the auto-increment column can also be 1. After the insert value is specified, the auto-increment column is inserted, the auto-increment is continued. Add and delete fields as follows:
 
Alter table student add age int; alter table student drop age;

Add and delete unique constraints

 
Alter table student add constraint un_name unique (stuname); alter table student drop index un_name;

To be continued...

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.