Home Database Mysql Tutorial MYSQL和SQL语法对照_MySQL

MYSQL和SQL语法对照_MySQL

Jun 01, 2016 pm 02:00 PM
sheet database

一、资料定义 ddl(data definition language)
资料定语言是指对资料的格式和形态下定义的语言,他是每个资料库要建立时候时首先要面对的,举凡资料分哪些表格关系、表格内的有什麽栏位主键、表格和表格之间互相参考的关系等等,都是在开始的时候所必须规划好的。
1、建表格:
create table table_name(
column1 datatype [not null] [not null primary key],
column2 datatype [not null],
...);
说明:
datatype --是资料的格式,详见表。
nut null --可不可以允许资料有空的(尚未有资料填入)。
primary key --是本表的主键。
2、更改表格
alter table table_name
add column column_name datatype
说明:增加一个栏位(没有删除某个栏位的语法。
alter table table_name
add primary key (column_name)
说明:更改表得的定义把某个栏位设为主键。
alter table table_name
drop primary key (column_name)
说明:把主键的定义删除。
3、建立索引
create index index_name on table_name (column_name)
说明:对某个表格的栏位建立索引以增加查询时的速度。
4、删除
drop table_name
drop index_name
二、资料操作 dml (data manipulation language)
资料定义好之后接下来的就是资料的操作。资料的操作不外乎增加资料(insert)、查询资料(query)、更改资料(update) 、删除资料(delete)四种模式,以下分 别介绍他们的语法:
1、增加资料:
insert into table_name (column1,column2,...)
values ( value1,value2, ...)
说明:
1.若没有指定column 系统则会按表格内的栏位顺序填入资料。
2.栏位的资料形态和所填入的资料必须吻合。
3.table_name 也可以是景观 view_name。
insert into table_name (column1,column2,...)
select columnx,columny,... from another_table
说明:也可以经过一个子查询(subquery)把别的表格的资料填入。
2、查询资料:
基本查询
select column1,columns2,...
from table_name
说明:把table_name 的特定栏位资料全部列出来
select *
from table_name
where column1 = xxx
[and column2 > yyy] [or column3 zzz]
说明:
1./'*/'表示全部的栏位都列出来。
2.where 之后是接条件式,把符合条件的资料列出来。
select column1,column2
from table_name
order by column2 [desc]
说明:order by 是指定以某个栏位做排序,[desc]是指从大到小排列,若没有指明,则是从小到大
排列
组合查询
组合查询是指所查询得资料来源并不只有单一的表格,而是联合一个以上的表格才能够得到结果的。
select *
from table1,table2
where table1.colum1=table2.column1
说明:
1.查询两个表格中其中 column1 值相同的资料。
2.当然两个表格相互比较的栏位,其资料形态必须相同。
3.一个复杂的查询其动用到的表格可能会很多个。
整合性的查询:
select count (*)
from table_name
where column_name = xxx
说明:
查询符合条件的资料共有几笔。
select sum(column1)
from table_name
说明:
1.计算出总和,所选的栏位必须是可数的数字形态。
2.除此以外还有 avg() 是计算平均、max()、min()计算最大最小值的整合性查询。
select column1,avg(column2)
from table_name
group by column1
having avg(column2) > xxx
说明:
1.group by: 以column1 为一组计算 column2 的平均值必须和 avg、sum等整合性查询的关键字一起使用。
2.having : 必须和 group by 一起使用作为整合性的限制。
复合性的查询
select *
from table_name1
where exists (
select *
from table_name2
where conditions )
说明:
1.where 的 conditions 可以是另外一个的 query。
2.exists 在此是指存在与否。
select *
from table_name1
where column1 in (
select column1
from table_name2
where conditions )
说明:
1. in 后面接的是一个集合,表示column1 存在集合里面。
2. select 出来的资料形态必须符合 column1。
其他查询
select *
from table_name1
where column1 like /'x%/'
说明:like 必须和后面的/'x%/' 相呼应表示以 x为开头的字串。
select *
from table_name1
where column1 in (/'xxx/',/'yyy/',..)
说明:in 后面接的是一个集合,表示column1 存在集合里面。
select *
from table_name1
where column1 between xx and yy
说明:between 表示 column1 的值介於 xx 和 yy 之间。
3、更改资料:
update table_name
set column1=/'xxx/'
where conditoins
说明:
1.更改某个栏位设定其值为/'xxx/'。
2.conditions 是所要符合的条件、若没有 where 则整个 table 的那个栏位都会全部被更改。
4、删除资料:
delete from table_name
where conditions
说明:删除符合条件的资料。
说明:关于where条件后面如果包含有日期的比较,不同数据库有不同的表达式。具体如下:
(1)如果是access数据库,则为:where mydate>#2000-01-01#
(2)如果是oracle数据库,则为:where mydate>cast(/'2000-01-01/' as date) 或:where mydate>to_date(/'2000-01-01/',/'yyyy-mm-dd/')
在delphi中写成:
thedate=/'2000-01-01/';
query1.sql.add(/'select * from abc where mydate>cast(/'+/'/'/'/'+thedate+/'/'/'/'+/' as date)/');
如果比较日期时间型,则为:
where mydatetime>to_date(/'2000-01-01 10:00:01/',/'yyyy-mm-dd hh24:mi:ss/');

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Steps to adjust the format of pictures inserted in PPT tables Steps to adjust the format of pictures inserted in PPT tables Mar 26, 2024 pm 04:16 PM

1. Create a new PPT file and name it [PPT Tips] as an example. 2. Double-click [PPT Tips] to open the PPT file. 3. Insert a table with two rows and two columns as an example. 4. Double-click on the border of the table, and the [Design] option will appear on the upper toolbar. 5. Click the [Shading] option and click [Picture]. 6. Click [Picture] to pop up the fill options dialog box with the picture as the background. 7. Find the tray you want to insert in the directory and click OK to insert the picture. 8. Right-click on the table box to bring up the settings dialog box. 9. Click [Format Cells] and check [Tile images as shading]. 10. Set [Center], [Mirror] and other functions you need, and click OK. Note: The default is for pictures to be filled in the table

How to set WPS value to automatically change color according to conditions_Steps to set WPS table value to automatically change color according to condition How to set WPS value to automatically change color according to conditions_Steps to set WPS table value to automatically change color according to condition Mar 27, 2024 pm 07:30 PM

1. Open the worksheet and find the [Start]-[Conditional Formatting] button. 2. Click Column Selection and select the column to which conditional formatting will be added. 3. Click the [Conditional Formatting] button to bring up the option menu. 4. Select [Highlight conditional rules]-[Between]. 5. Fill in the rules: 20, 24, dark green text with dark fill color. 6. After confirmation, the data in the selected column will be colored with corresponding numbers, text, and cell boxes according to the settings. 7. Conditional rules without conflicts can be added repeatedly, but for conflicting rules WPS will replace the previously established conditional rules with the last added rule. 8. Repeatedly add the cell columns after [Between] rules 20-24 and [Less than] 20. 9. If you need to change the rules, you can just clear the rules and then reset the rules.

How to make a table for sales forecast How to make a table for sales forecast Mar 20, 2024 pm 03:06 PM

Being able to skillfully make forms is not only a necessary skill for accounting, human resources, and finance. For many sales staff, learning to make forms is also very important. Because the data related to sales is very large and complex, and it cannot be simply recorded in a document to explain the problem. In order to enable more sales staff to be proficient in using Excel to make tables, the editor will introduce the table making issues about sales forecasting. Friends in need should not miss it! 1. Open [Sales Forecast and Target Setting], xlsm, to analyze the data stored in each table. 2. Create a new [Blank Worksheet], select [Cell], and enter [Label Information]. [Drag] downward and [Fill] the month. Enter [Other] data and click [

How to use JavaScript to implement drag-and-drop adjustment of table column width? How to use JavaScript to implement drag-and-drop adjustment of table column width? Oct 21, 2023 am 08:14 AM

How to use JavaScript to realize the drag-and-drop adjustment function of table column width? With the development of Web technology, more and more data are displayed on web pages in the form of tables. However, sometimes the column width of the table cannot meet our needs, and the content may overflow or the width may be insufficient. In order to solve this problem, we can use JavaScript to implement the drag-and-drop adjustment function of the column width of the table, so that users can freely adjust the column width according to their needs. To realize the drag-and-drop adjustment function of table column width, the following three main points are required:

How to remove duplicate borders of table in css How to remove duplicate borders of table in css Sep 29, 2021 pm 06:05 PM

In CSS, you can use the border-collapse attribute to remove duplicate borders in the table. This attribute can set whether the table border is collapsed into a single border or separated. You only need to set the value to collapse to merge overlapping borders together. Become a border to achieve the effect of a single line border.

What should I do if the form cannot be printed outside the dotted line? What should I do if the form cannot be printed outside the dotted line? Mar 28, 2023 am 11:38 AM

Solution to the problem that the table cannot be printed outside the dotted line: 1. Open the excel file and click "Print" on the opened page; 2. Find "No Zoom" on the preview page and select to adjust to one page; 3. Select the printer to print. Documentation is enough.

How to export and import table data in Vue How to export and import table data in Vue Oct 15, 2023 am 08:30 AM

How to implement the export and import of tabular data in Vue requires specific code examples. In web projects developed using Vue, we often encounter the need to export tabular data to Excel or import Excel files. This article will introduce how to use Vue to implement the export and import functions of table data, and provide specific code examples. 1. Installation dependencies for exporting table data First, we need to install some dependencies for exporting Excel files. Run the following command from the command line in your Vue project: npmin

Using JavaScript to implement paging display of table data Using JavaScript to implement paging display of table data Jun 16, 2023 am 10:00 AM

As data continues to grow, tabular display becomes more difficult. Most of the time, the amount of data in a table is so large that it becomes slow to load and users need to constantly browse the page to find the data they want. This article will introduce how to use JavaScript to realize paginated display of table data, making it easier for users to find the data they want. 1. Dynamically create tables. In order to make the paging function more controllable, tables need to be created dynamically. In the HTML page, add a table element similar to the one below.

See all articles