Home Database Mysql Tutorial MySql WorkBench基本使用以及基本sql语句_MySQL

MySql WorkBench基本使用以及基本sql语句_MySQL

Jun 01, 2016 pm 01:36 PM
oracle sql statement data

bitsCN.com

导读:
本篇文章会教你如何使用My Sql WorkBench 5.2 进行数据库的基本操作(建库建表等)
前言
MySql是甲骨文公司的产物,所以有些地方跟Oracle挺相似,比如“服务器实例”这个概念,当初由sqlserver转Oracle的时候,一开始就不理解这个服务器实例是个什么东西,因为在SqlServer里,就只有一个服务器,登录之后就是操作数据库,基本上就是一个项目对应一个数据库。

但有的项目很庞大,需要创建很多的数据库,多个数据都是属于同一个项目,然后这时候就可以创建一个服务器实例,可以把需要的数据库创建在这个实例下,创建好服务器实例后,会给这个实例分配一个端口(这是必然的,因为已经是服务器了嘛)也会在Windows系统 服务列表添加相应的服务,这时候你就应该更深刻的了解什么是服务器实例了。基本上是:一个项目对应一个服务器实例。
创建服务器实例
由于还没有研究透,所以先空着,以后会加上,我的是在安装的时候就选了创建默认服务器实例,现在就拿它做下面的示范

创建数据库
双击要连接的服务器实例
MySql WorkBench基本使用以及基本sql语句_MySQL
输入密码进入之后,选择DataBase→Query Database
MySql WorkBench基本使用以及基本sql语句_MySQL
选择OK,创建了一个新页面
MySql WorkBench基本使用以及基本sql语句_MySQL
左侧的树就是该服务器实例下的所有数据库列表,中间部分就是执行sql语句的地方,执行如图的sql语句(单击小闪电图标),创建一个数据库,在左侧的树形结构里,随便右击一个东西,选择Refresh All,新数据库出来了
注:我的数据库文件存储在E:/ProgramData/MySQL/MySQL Server 5.5/data   盘符自己对应
一个数据库就是一个文件夹
创建数据表

[sql] 
 

use ceshi;  
create table student  
(  
    stuid int primary key auto_increment,  
    stuName varchar(40) not null  
);  


这样就创建了一个studeng表,auto_increment是自增列的意思

插入数据

[sql] 
 

insert into student(stuname) values('zhangsan');  
insert into student value(2,'lisi');  
insert into student value(10,'wangwu');  
insert into student(stuName) value('maliu');  

这样就插入了4条数据,并且测试了自增列插入的方法,

如果语句里不指定插入自增列,则默认是从1开始,自增量是1
也可以指定插入自增列的值,指定插入值之后,再自增插入,则继续自增。4条数据如下

MySql WorkBench基本使用以及基本sql语句_MySQL

添加删除字段

[sql] 
 

alter table student  add age int ;  
alter table student drop age;  


添加删除唯一约束

[sql] 
 

alter table student add constraint UN_Name unique(stuName);  
alter table student drop index UN_Name;  


bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

How to check invalid numbers of oracle How to check invalid numbers of oracle Apr 11, 2025 pm 08:27 PM

Oracle Invalid numeric errors may be caused by data type mismatch, numeric overflow, data conversion errors, or data corruption. Troubleshooting steps include checking data types, detecting digital overflows, checking data conversions, checking data corruption, and exploring other possible solutions such as configuring the NLS_NUMERIC_CHARACTERS parameter and enabling data verification logging.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to delete all data from oracle How to delete all data from oracle Apr 11, 2025 pm 08:36 PM

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to read the oracle awr report How to read the oracle awr report Apr 11, 2025 pm 09:45 PM

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.

See all articles