Category SQL language and common data types

Category SQL language and common data types

SQL language classification

Data Definition Language DDL

DDL mainly on database objects to create, modify, delete operations (create, alter, drop), database objects, including databases, tables, views, indexes;

-- 创建表
create table table_name(
   列名 数据类型 [键约束],
   ......,
   [约束]
);

-- 修改表
alter table table_name add|modify|drop column_name;
   -- add|modify|drop 即向表中添加列、修改列、删除列

-- 删除表
drop table table_name;

Data Manipulation Language DML

DML mainly on a database table insert, modify, delete operations (insert, update, delete);

-- 插入数据
insert into table_name(column_name1,column_name2....) values(data1,data2....);
  
   -- 通过其他数据表添加数据(查找的数据列要与插入的数据列匹配)
   insert into user(u_name) select p_name from person;
   
-- 修改数据
update table_name set column_name = 'data' [where condition];

-- 修改数据 merge (执行语境:向表1插入或更新数据,满足条件插入,不满足则更新)
merge [into] table1 using table2 on condition
   when matched then insert_clause
   when not matched then update_clause;

-- 删除数据
delete from table_name [where condition];

-- 删除数据 truncate
truncate table tabel_name;

Data query language DQL

DQL main operation (select) data database query tables;

Data Control Language DCL

DCL is the main operating grant permissions to the database object permissions, and recover permissions, submit, save point, rollback, set affairs (grant, revoke, commit, savepoint, rollback, set transaction);

Common data types

11g supports 23 data types, data types described below common character, numeric, date, type, other types;

Character

Character has char, varchar,nchar,nvarchar,longfive kinds

type of data Range (bytes) Explanation
char 0 -2000 Fixed-length character
nchar 0-1000 Unicode character set fixed-length character
varchar 0-4000 Variable character
nvarchar 0-1000 Unicode character set variable character
long 0-2GB Variable character (rarely used)

Numeric

There are digital type number, float

type of data Ranges Explanation
number(p,s) p maximum precision of 38 (decimal) p represents precision, s represent reserved decimal places, for storing fixed-length integer and fractional
float Maximum resolution 126 (binary) 1-126 accuracy range is binary converted into decimal multiplied by 0.30103

Date Type

Date types are divideddate, timestamp

type of data Explanation
date Used to store the date and time (-? 9999-12-31)
timestamp Stores the date and time, and more accurate than the date

Other data types

type of data Ranges Explanation
blob 4GB Store binary
clob 4GB Store strings
bfile Size associated with the operating system The operating system files unstructured binary data stored outside the database

Guess you like

Origin www.cnblogs.com/f1ynn/p/11619461.html