Guidance:
This article will teach you how to use My SQL WorkBench 5.2 to perform basic database operations (create databases and tables)
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.
Www.2cto.com
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.
Create a server instance
Since it has not been thoroughly studied, I will leave it blank first. I will add it later. I chose to create a default server instance during installation. Now I will use it for the following demonstration.
Www.2cto.com
Create a database
Double-click the server instance to be connected
After entering the password, select DataBase> Query Database
Select OK to create a new page
The tree on the left 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 myself
A database is a folder.
Create a data table [SQL]
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 [SQL].
Insert into student (stuname) values ('hangsan ');
Insert into student value (2, 'lisi ');
Insert into student value (10, 'hangzhou ');
Insert into student (stuName) value ('maliu '); This inserts four data records and tests the auto-increment column insertion method. If the insert auto-increment column is not specified in the statement, the default value is from 1 and the auto increment value is 1.
You can also specify the value of the inserted auto-increment column. After the inserted value is specified, the auto-increment column is inserted. The four data entries are as follows:
Www.2cto.com
Add and delete a field [SQL]
Alter table student add age int;
Alter table student drop age; www.2cto.com
Add and delete the unique constraint [SQL]
Alter table student add constraint UN_Name unique (stuName );
Alter table student drop index UN_Name;