ddl

To improve SQL-queries in DDL

耗尽温柔 提交于 2019-11-29 16:58:02
Improvements done nvarchar(5000) -> nvarchar(4000) BUT no nvarchar in PostgreSQL => TEXT memory limits to some variables the syntax slightly changed to more readable dashes to underscores Magnus' improvements I am following my plan for my first database project . I would like to know any weaknesses in the queries and in the relational table. SQL-queries in DDL CREATE TABLE answers ( question_id INTEGER FOREIGN KEY REFERENCES questions(user_id) PRIMARY KEY CHECK (user_id>0), answer TEXT NOT NULL -- answer must have text ); CREATE TABLE questions ( user_id INTEGER FOREIGN KEY REFERENCES user

postgres csv日志和查看用户权限

喜欢而已 提交于 2019-11-29 15:34:50
postgres csv日志和查看用户权限 最近在使用postgres 时遇到的2个问题,顺便记录一下查到的比较好的资料。 怀疑postgres在执行SQL时报错,程序日志中有无明确异常信息。通过查看csv日志来确定是否SQL真的是执行时报错。 下面转自: https://www.cnblogs.com/kuang17/p/6902122.html?utm_source=itdadao&utm_medium=referral   日志审计   审计是值记录用户的登陆退出以及登陆后在数据库里的行为操作,可以根据安全等级不一样设置不一样级别的审计,   此处涉及的参数文件有:   logging_collector --是否开启日志收集开关,默认off,开启要重启DB   log_destination --日志记录类型,默认是stderr,只记录错误输出   log_directory --日志路径,默认是$PGDATA/pg_log, 这个目录最好不要和数据文件的目录放在一起, 目录需要给启动postgres的操作系统用户写权限.   log_filename --日志名称,默认是postgresql-%Y-%m-%d_%H%M%S.log   log_file_mode --日志文件类型,默认为0600   log_truncate_on_rotation --默认为off

How to delete unused sequences?

≡放荡痞女 提交于 2019-11-29 14:54:16
问题 We are using PostgreSQL. My requirement is to delete unused sequences from my database. For example, if I create any table through my application, one sequence will be created, but for deleting the table we are not deleting the sequence, too. If want to create the same table another sequence is being created. Example: table: file ; automatically created sequence for id coumn: file_id_seq When I delete the table file and create it with same name again, a new sequence is being created (i.e.

DDL statements in PL/SQL?

纵然是瞬间 提交于 2019-11-29 14:33:46
I am trying the code below to create a table in PL/SQL : DECLARE V_NAME VARCHAR2(20); BEGIN EXECUTE IMMEDIATE 'CREATE TABLE TEMP(NAME VARCHAR(20))'; EXECUTE IMMEDIATE 'INSERT INTO TEMP VALUES(''XYZ'')'; SELECT NAME INTO V_NAME FROM TEMP; END; / The SELECT statement fails with this error: PL/SQL: ORA-00942: table or view does not exist Is it possible to CREATE, INSERT and SELECT all in a single PL/SQL Block one after other? Ben I assume you're doing something like the following: declare v_temp varchar2(20); begin execute immediate 'create table temp(name varchar(20))'; execute immediate 'insert

SQL命令分类(DDL、DML、DCL、TCL以及事务)

▼魔方 西西 提交于 2019-11-29 11:58:56
DDL(数据库定义语言) :create创建、alter修改、drop删除、truncate截断、comment注释、rename重命名。 DDL不需要commit命令(提交、确认、生效) DML(数据库操纵语言) :select查询记录、insert插入记录、update更新记录、delete删除记录、explain plan执行计划、lock table锁表、merge 、call调用。 DML需要commit才能生效。 DCL(数据库控制语言) :grant授权、revoke取消授权。 TCL(事务控制语言) :事务是一个不可分割的工作逻辑单元、可以使用事务来保证数据库的一致性和可恢复性。 事务中的sql语句,成功都成功,失败都失败 。 事务的ACID特性:原子性、一致性、隔离性、持久性。 来源: https://blog.csdn.net/leilei7407/article/details/100804402

DML、DDL、DCL是什么?

不羁岁月 提交于 2019-11-29 11:44:44
一、DML   DML(data manipulation language)数据操纵语言:     我们经常会用到的 INSERT、DELETE、UPDATE、SELECT语句。 主要用来对数据库的数据进行一些操作。 INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....) DELETE FROM 表名称 WHERE 列名称 = 值 UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值 SELECT 列名称 FROM 表名称 二、DDL   DDL(data definition language)数据库定义语言,如:   CREATE:创建    ALTER:修改表结构    RENAME:修改表名或列名    DROP:删除表中的数据和结构,删除后不能回滚    TRUNCATE:删除表中的数据不删除表结构,删除后不能回滚,效率比DELETE高   其实就是我们在创建表的时候用到的一些sql,比如说:CREATE、ALTER、DROP等。DDL主要是用在定义或改变表的结构,数据类型,表之间的链接和约束等初始化工作上 CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据类型, 列名称3 数据类型, .... ) ALTER TABLE table_name ALTER

Alter table after keyword in Oracle

丶灬走出姿态 提交于 2019-11-29 09:33:16
ALTER TABLE testTable ADD column1 NUMBER(1) DEFAULT 0 NOT NULL AFTER column2; Why can't I use mySql syntax in Oracle too? The above command works in MySql. Can you give me an equivalent that works? Error report: SQL Error: ORA-01735: invalid ALTER TABLE option 01735. 00000 - "invalid ALTER TABLE option" I am asking if there is any way to use after clause in Oracle command that I provided? Because SQL is a relational algebra. It doesn't care one bit about "where" columns are located within a table, only that they exist. To get it to work in Oracle, just get rid of the after clause. The Oracle

Why can I create a table with PRIMARY KEY on a nullable column?

蓝咒 提交于 2019-11-29 09:05:54
The following code creates a table without raising any errors: CREATE TABLE test( ID INTEGER NULL, CONSTRAINT PK_test PRIMARY KEY(ID) ) Note that I cannot insert a NULL, as expected: INSERT INTO test VALUES(1),(NULL) ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null). ********** Error ********** ERROR: null value in column "id" violates not-null constraint SQL state: 23502 Detail: Failing row contains (null). Why can I create a table with a self-contradictory definition? ID column is explicitly declared as NULLable, and it is implicitly not

各个SQL语法的差异比较

…衆ロ難τιáo~ 提交于 2019-11-29 08:28:22
本文将从SQL角度,将MaxCompute SQL与Hive、MySQL、Oracle、SQL Server进行对比,从而为您介绍MaxCompute不支持的DDL和DML语法。 MaxCompute不支持的DDL语法 语法 MaxCompute Hive MySQL Oracle SQL Server CREATE TABLE—PRIMARY KEY N N Y Y Y CREATE TABLE—NOT NULL N N Y Y Y CREATE TABLE—CLUSTER BY Y Y N Y Y CREATE TABLE—EXTERNAL TABLE Y (OSS, OTS, TDDL) Y N N N CREATE TABLE—TEMPORARY TABLE N Y Y Y Y (with #prefix) INDEX—CREATE INDEX N Y Y Y Y VIRTUAL COLUMN N N (only 2 predefined) N Y Y MaxCompute不支持的DML语法 语法 MaxCompute Hive MySQL Oracle SQL Server CTE(公共表达式) Y Y Y Y Y SELECT—recursive CTE(递归公共表达式) N N N Y Y SELECT—GROUP BY ROLL UP Y Y Y Y Y

Hive DDL语法

前提是你 提交于 2019-11-29 08:27:51
DDL语法 1. 数据库操作 创建一个数据库会在HDFS上创建一个目录,Hive里数据库的概念类似于程序中的命名空间,用数据库来组织表,在大量Hive的情况下,用数据库来分开可以避免表名冲突。Hive默认的数据库是default。 hive不能使用关键字、数字开始的字符串来作库表名,不区分大小写。 1.1 创建数据库例子: hive > create database [ if not exists ] db1 ; []中的可以不写,判断是否存在 1.2 查看数据库定义: Describe 命令来查看数据库定义,包括:数据库名称、数据库在HDFS目录、HDFS用户名称。 hive > desc database db1 ; OK db1 hdfs: //cluster1/user/hive/warehouse/db1.db root USER Time taken: 0.059 seconds , Fetched: 1 row ( s ) db1是数据库名称。 hdfs://cluster1/user/hive/warehouse/db1.db 是db1库对应的存储数据的HDFS上的根目录。 1.3 查看数据库列表: hive > show databases ; OK db1 default Time taken: 0.036 seconds , Fetched: 2 row (