ddl

Liquibase/PostgreSQL: how to preserve table case correctly?

こ雲淡風輕ζ 提交于 2019-11-28 05:01:52
问题 I'm using Liquibase 3.1.1 to create tables in PostgreSQL 9.1. For example: <changeSet id="1" author="bob"> <createTable tableName="BATCHES"> <!-- .. -- > </createTable> </changeSet> However, the table gets created with a lowercase name: # select * from "BATCHES"; ERROR: relation "BATCHES" does not exist Is there any way to have Liquibase generate DDL that preserves the case of the table (and column etc) names that I specify in the change log? 回答1: You can use the objectQuotingStrategy="QUOTE

Truncating a table in a stored procedure

爱⌒轻易说出口 提交于 2019-11-28 04:50:54
When I run the following in an Oracle shell it works fine truncate table table_name But when I try to put it in a stored procedure CREATE OR REPLACE PROCEDURE test IS BEGIN truncate table table_name; END test; / it fails with ERROR line 3, col 14, ending_line 3, ending_col 18, Found 'table', Expecting: @ ROW or ( or . or ; := Why? Dheer All DDL statements in Oracle PL/SQL should use Execute Immediate before the statement. Hence you should use: execute immediate 'truncate table schema.tablename'; As well as execute immediate you can also use DBMS_UTILITY.EXEC_DDL_STATEMENT('TRUNCATE TABLE

How do I use CREATE OR REPLACE?

自古美人都是妖i 提交于 2019-11-28 04:02:13
Am I correct in understanding that CREATE OR REPLACE basically means "if the object exists, drop it, then create it either way?" If so, what am I doing wrong? This works: CREATE TABLE foo (id NUMBER, title VARCHAR2(4000) DEFAULT 'Default Title') And this doesn't (ORA-00922: missing or invalid option): CREATE OR REPLACE TABLE foo (id NUMBER, title VARCHAR2(4000) DEFAULT 'Default Title') Am I doing something stupid? I don't seem to be able to find much documentation about this syntax. This works on functions, procedures, packages, types, synonyms, trigger and views. Update: After updating the

Alter table after keyword in Oracle

陌路散爱 提交于 2019-11-28 02:59:20
问题 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? 回答1: Because SQL is a relational algebra. It doesn't care one bit about "where" columns are located

Create user from string variables in a PL/SQL block

天涯浪子 提交于 2019-11-28 02:06:36
I use Oracle XE for the sole purpose of developing PHP applications and version 11g has apparently lost the GUI tool to manage users which 10g used to have so I'd like to prepare a code snippet to create users from command line. I'm trying to define variables so I don't need to type the same user name 16 times but I can't get the syntax right: DECLARE my_user VARCHAR2(30) := 'foo'; my_password VARCHAR2(9) := '1234'; BEGIN CREATE USER my_user IDENTIFIED BY my_password DEFAULT TABLESPACE users; GRANT CONNECT, RESOURCE TO my_user; GRANT CREATE DATABASE LINK TO my_user; GRANT CREATE MATERIALIZED

How can I generate (or get) a ddl script on an existing table in oracle? I have to re-create them in Hive

夙愿已清 提交于 2019-11-28 00:03:50
How can I generate a DDL script on an existing table in oracle? I am working on a project where I have to re-create some tables that are present in Oracle table into Hive. If your SQL client doesn't support this, then you can use the dbms_metadata package to get the source for nearly everything in your database: For a table use something like this: select dbms_metadata.get_ddl('TABLE', 'YOUR_TABLE_NAME') from dual; You can also do this for all tables at once: select dbms_metadata.get_ddl('TABLE', table_name) from user_tables; and spool the output into a SQL script. More details are in the

Invalid column name on sql server update after column create

霸气de小男生 提交于 2019-11-27 23:30:02
Does anyone see what's wrong with this code for SQL Server? IF NOT EXISTS(SELECT * FROM sys.columns WHERE Name = 'OPT_LOCK' AND object_ID = Object_id('REP_DSGN_SEC_GRP_LNK')) BEGIN ALTER TABLE REP_DSGN_SEC_GRP_LNK ADD OPT_LOCK NUMERIC(10, 0) UPDATE REP_DSGN_SEC_GRP_LNK SET OPT_LOCK = 0 ALTER TABLE REP_DSGN_SEC_GRP_LNK ALTER COLUMN OPT_LOCK NUMERIC(10, 0) NOT NULL END; When I run this, I get: Msg 207, Level 16, State 1, Line 3 Invalid column name 'OPT_LOCK'. on the update command. Thanks. Martin Smith In this case you can avoid the problem by adding the column as NOT NULL and setting the values

How can I drop all indexes of a table in Postgres?

◇◆丶佛笑我妖孽 提交于 2019-11-27 21:41:59
问题 I keep having this problem: I have like 20 indexes on a table that I need to drop in order to do testing. Dropping the table doesn't drop all of this metadata. There doesn't seem to be a wildcard drop index ix_table_* or any useful command. There seem to be some bash loops around psql you can write. There must be something better! Thoughts? 回答1: Assuming you only want to drop plain indexes: DO $$BEGIN EXECUTE ( SELECT 'DROP INDEX ' || string_agg(indexrelid::regclass::text, ', ') FROM pg_index

Do DDL statements always give you an implicit commit, or can you get an implicit rollback?

时光怂恿深爱的人放手 提交于 2019-11-27 20:41:04
If you're halfway through a transaction and perform a DDL statement, such as truncating a table, then the transaction commits. I was wondering whether this was always the case and by definition, or is there a setting hidden somewhere that would rollback the transaction instead of committing. Thanks. Edit to clarify... I'm not looking to rollback after a truncate. I just want to confirm that statements already carried out are absolutely always going to be committed before a DDL. Just want to make sure there isn't a system property somewhere that someone could set to wreck my code. I understand

MYSQL入门操作和常规DML、DDL、DQL使用

ⅰ亾dé卋堺 提交于 2019-11-27 18:04:09
刷新权限,将某些权限从硬盘刷新到内存中(修改root密码自带隐式刷新权限操作) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> 查看服务端口 mysql> show variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.00 sec) mysql> 查看数据库字符集 mysql> show variables like '%char%'; +--------------------------+----------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database |