MySQL replication and data table syntax example

First, let us talk about desc, MySQL has two desc

The first desc (describe, description) is a command mysql

desc stu1  //查看表stu的表表结构

The second desc (descend, decrease) the corresponding values ​​in descending order, with the sql statement

Second, then talk about the tables and table data replication statements

Stu] [MySQL table in descending order (ascending order by default), and inserted to limit the scope of the recording stu1

insert into `stu1` select * FROM `stu`  ORDER BY `id` DESC LIMIT 100 (或者0,100) 
//前100条记录复制到表stu(表面和字段用单引号或无引号均可)
insert into `6`(sid,xm)  select  sf,cs from `stu5` ORDER BY `id` DESC limit 2  
//表stu5前2条记录的字段sf,cs值插入(追加)到表stu的sid,xm字段列(不一定要是同名字段)

[MySQL] to create a new table stu4, stu copy of the table structure and content , but does not include an index

CREATE TABLE stu4 SELECT * FROM stu2
CREATE TABLE stu6 AS (SELECT * FROM stu3) //同上一句作用一样
CREATE TABLE stu8 AS (SELECT id, xm FROM stu3)  //只复制id,xm两个字段
CREATE TABLE stu7 AS (SELECT ID AS SID,xm AS xm1,bh AS bh1 FROM `stu1`)
//复制ID,xm,bh 三个字段,并对这些字段进行了重命名
CREATE TABLE stu9 SELECT ID AS SID,xm AS xm1,bh AS bh1 FROM `stu1`
//作用同上,不用as也可以

[MySQL] fully replicated table structure (including indexes and primary keys), but does not copy the contents of

CREATE TABLE stu3 LIKE stu

[MySQL] fully replicated table structure and content. Note that these are two statements must be used; connection, otherwise an error

create table stu6 like stu;
instert into stu6 SELECT * FROM stu2

Third, before viewing table 100 records a few grammar contrast common database

SQL query to display the first 100 results

MYSQL:

select * from tbl limit 100;

ORACLE:

select * from tbl where rownum<=100;

SQL SERVER:

select top 100 * from tbl

SYBASE:

SET ROWCOUNT N GOSELECT * FROM TABLE1 

Guess you like

Origin www.cnblogs.com/al88/p/12412065.html