Talk about writing sql database

This article for beginners a superficial introduction to the relationship between the number of type library, if you want in-depth understanding must be separate in-depth study for each content mentioned below!

 

it-information technology for short, is a Chinese information machine technology, in fact, the information data.

Data to be processed, then at least involves several aspects:

1) expression

2) Access

3) calculation

4) Safety

Or otherwise, of course!

The second point which is the core mission of the database.

An industrial grade product far from this, there are:

1) Network

2) Concurrent

3) Performance

4) Programming

5) security (including access to data encryption + and the like)

6) Backup / Restore

7) high reliability

8) compatible

Etc., each of which is possible in-depth study!

 

With the development of the database, the database more autonomy (optimized, high reliability, etc.), for ordinary dba concerned, a lot easier than before.

 

For most programmers, database and must do interact, both front-end or back-end

This article deals with a traditional relational database, focuses on several points:

1) Installation

2) backup and recovery

3) Programming (sql)

These are very basic, belonging to the programmer must master basic skills!

 

First, install

Programmers of the most basic requirement, not installed then there is nothing to say! Specifically slightly, to emphasize that it should go back to install each operating system, in addition to the cluster version will be installed!

The basic installation steps:

1. Make sure that the range of functions

2. Verify that the free or paid

3. Download the installation package

4. Install

5 Configuration

6. Create an account administrator about

7. Configure and network security

Second, backup and recovery

      Cold backup may not be required, nor does it require professional does not back up, but it will require at least logical backup and recovery!

      oracle, to know how to expdp / impdp, mysql to know how to mysqldump, sqlserver to know how bcp and so on.

Third, the program

To be familiar with sql statement, you must understand a few basic elements:

1. relational database concepts

2. The principle of data storage, different rdbms memory is not the same, so learning a new one, you must understand one specific storage

3.sql language

4.sql-iso different manufacturers standards and implementations

 

1,2,3 must be mastered, a lack of, are difficult to prepare qualified sql statement!

In addition, many of the concepts also need to know: Paradigm, indexes, partitions, views, metadata, lock, cache, basic algorithms (FIFO, LRU, etc.), distributed database, and so on.

 

This article will be an example of Mysql8.x and oracle 12c!

 

3.1 relational database concepts

Focus is on "relationship", or can be understood as a form, you can have multiple columns and rows.

Kv mode is different from the database, but also from the big data-based hdfs, but now is different from the so-called block chain database!

The key is to satisfy the relational database acid:

a: atomic transaction is either completed or not completed

c: consistency, the associated data should be consistent with the business logic, before and after the transaction must preserve the integrity of the data. Can refer to the understanding of the law of conservation of energy, personal financial revenue and expenditure!

i: isolation, a transaction does not affect the other transaction, the transaction can be simply understood Hubuyingxiang

d: persistence, it is the data according to the floor, and stored on a specific medium, can not always live under state only!

ad easy to understand, but ic is not so easy, you need to read more documentation to deeply understand!

Note: relational databases follow acid, but different product implementations may vary, there are differences in performance!

 

 

3.2 Data storage

How data is stored, it is quite complex things, because it affects many aspects:

1. Performance

2. Safety and backup

3. Data show

For example: oracle12c

 

 

 

mysql-innodb

 

In fact, the relationship between memory and performance, you can find Lenovo library book, urban planning and other scenes, this is what we often say "Road interlinked," or theory from practice!

How to put the book to find quicker, more space, more secure, and so on?

How should urban transport planning in order to achieve maximum capacity, at the same time be able to benefit the most people?

Database of physical and logical storage system designed to improve the performance is very critical, is relatively complex.

 

To see the oracle and mysql create table statement, i can feel the storage is important, content is a lot to learn.

oracle:https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6

mysql: https://dev.mysql.com/doc/refman/8.0/en/create-table.html

Some stick out this command, it is estimated scalp saw a bear:

mysql:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    (create_definition,...)
    [table_options]
    [partition_options]

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    [(create_definition,...)]
    [table_options]
    [partition_options]
    [IGNORE | REPLACE]
    [AS] query_expression

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    { LIKE old_tbl_name | (LIKE old_tbl_name) }

create_definition:
    col_name column_definition
  | {INDEX|KEY} [index_name] [index_type] (key_part,...)
      [index_option] ...
  | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] PRIMARY KEY
      [index_type] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
      [index_name] [index_type] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] FOREIGN KEY
      [index_name] (col_name,...)
      reference_definition
  | check_constraint_definition

column_definition:
    data_type [NOT NULL | NULL] [DEFAULT {literal | (expr)} ]
      [AUTO_INCREMENT] [UNIQUE [KEY]] [[PRIMARY] KEY]
      [COMMENT 'string']
      [COLLATE collation_name]
      [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
      [STORAGE {DISK|MEMORY}]
      [reference_definition]
      [check_constraint_definition]
  | data_type
      [COLLATE collation_name]
      [GENERATED ALWAYS] AS (expr)
      [VIRTUAL | STORED] [NOT NULL | NULL]
      [UNIQUE [KEY]] [[PRIMARY] KEY]
      [COMMENT 'string']
      [reference_definition]
      [check_constraint_definition]

data_type:
    (see Chapter 11, Data Types)

key_part: {col_name [(length)] | (expr)} [ASC | DESC]

index_type:
    USING {BTREE | HASH}

index_option:
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name
  | COMMENT 'string'
  | {VISIBLE | INVISIBLE}

check_constraint_definition:
    [CONSTRAINT [symbol]] CHECK (expr) [[NOT] ENFORCED]

reference_definition:
    REFERENCES tbl_name (key_part,...)
      [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
      [ON DELETE reference_option]
      [ON UPDATE reference_option]

reference_option:
    RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT

table_options:
    table_option [[,] table_option] ...

table_option:
    AUTO_INCREMENT [=] value
  | AVG_ROW_LENGTH [=] value
  | [DEFAULT] CHARACTER SET [=] charset_name
  | CHECKSUM [=] {0 | 1}
  | [DEFAULT] COLLATE [=] collation_name
  | COMMENT [=] 'string'
  | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'}
  | CONNECTION [=] 'connect_string'
  | {DATA|INDEX} DIRECTORY [=] 'absolute path to directory'
  | DELAY_KEY_WRITE [=] {0 | 1}
  | ENCRYPTION [=] {'Y' | 'N'}
  | ENGINE [=] engine_name
  | INSERT_METHOD [=] { NO | FIRST | LAST }
  | KEY_BLOCK_SIZE [=] value
  | MAX_ROWS [=] value
  | MIN_ROWS [=] value
  | PACK_KEYS [=] {0 | 1 | DEFAULT}
  | PASSWORD [=] 'string'
  | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
  | STATS_AUTO_RECALC [=] {DEFAULT|0|1}
  | STATS_PERSISTENT [=] {DEFAULT|0|1}
  | STATS_SAMPLE_PAGES [=] value
  | TABLESPACE tablespace_name [STORAGE {DISK|MEMORY}]
  | UNION [=] (tbl_name[,tbl_name]...)

partition_options:
    PARTITION BY
        { [LINEAR] HASH(expr)
        | [LINEAR] KEY [ALGORITHM={1|2}] (column_list)
        | RANGE{(expr) | COLUMNS(column_list)}
        | LIST{(expr) | COLUMNS(column_list)} }
    [PARTITIONS num]
    [SUBPARTITION BY
        { [LINEAR] HASH(expr)
        | [LINEAR] KEY [ALGORITHM={1|2}] (column_list) }
      [SUBPARTITIONS num]
    ]
    [(partition_definition [, partition_definition] ...)]

partition_definition:
    PARTITION partition_name
        [VALUES
            {LESS THAN {(expr | value_list) | MAXVALUE}
            |
            IN (value_list)}]
        [[STORAGE] ENGINE [=] engine_name]
        [COMMENT [=] 'string' ]
        [DATA DIRECTORY [=] 'data_dir']
        [INDEX DIRECTORY [=] 'index_dir']
        [MAX_ROWS [=] max_number_of_rows]
        [MIN_ROWS [=] min_number_of_rows]
        [TABLESPACE [=] tablespace_name]
        [(subpartition_definition [, subpartition_definition] ...)]

subpartition_definition:
    SUBPARTITION logical_name
        [[STORAGE] ENGINE [=] engine_name]
        [COMMENT [=] 'string' ]
        [DATA DIRECTORY [=] 'data_dir']
        [INDEX DIRECTORY [=] 'index_dir']
        [MAX_ROWS [=] max_number_of_rows]
        [MIN_ROWS [=] min_number_of_rows]
        [TABLESPACE [=] tablespace_name]

query_expression:
    SELECT ...   (Some valid select or union statement)

  顺便说下:如果英文不过关,那么学好计算机还是有一定难度的!毕竟许多资料是英文的!

3.3 sql语句

   标准sql语句,尤其是ddl,dml语句谈不上复杂,准确说,应该是相对很简单的。

   如果有什么稍微难一些的就是 集合运算,譬如 inner join ,left join,full join,但也很容易理解!

  

总结

   要写好sql语句,需要长时间训练,从数据库基础开始,到熟练写出每个sql语句!

   学习之后,写不出每个sql语句,属于资质问题;写不出好的sql语句,可能是学习不够,也可能是资质问题!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lzfhope/p/12087846.html