ddl

Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?

半世苍凉 提交于 2019-11-26 19:54:47
I want to create a database which does not exist through JDBC. Unlike MySQL, PostgreSQL does not support create if not exists syntax. What is the best way to accomplish this? The application does not know if the database exists or not. It should check and if the database exists it should be used. So it makes sense to connect to the desired database and if connection fails due to non-existence of database it should create new database (by connecting to the default postgres database). I checked the error code returned by Postgres but I could not find any relevant code that species the same.

How to generate entire DDL of an Oracle schema (scriptable)?

ε祈祈猫儿з 提交于 2019-11-26 19:41:55
Can anyone tell me how I can generate the DDL for all tables, views, indexes, packages, procedures, functions, triggers, types, sequences, synonyms, grants, etc. inside an Oracle schema? Ideally, I would like to copy the rows too but that is less important. I want to do this on a scheduled job of some kind and not manually each time, so that rules out using the wizard in SQL Developer. Ideally, since I will be running this on several schemas that have grants and synonyms to one another, I would like to have a way to do a find/replace in the output so the schema names match whatever the names

How to create a Foreign Key with “ON UPDATE CASCADE” on Oracle?

微笑、不失礼 提交于 2019-11-26 17:24:56
问题 In MS SQL Server it is possible to create a foreign key with ON UPDATE CASCADE option, so whenever you update one of the columns in the primary key, the foreign keys in other tables will also be update by the DBMS. So, how to do it in Oracle? 回答1: Oracle does not allow a Foreign Key constraint with “ON UPDATE CASCADE”. Here are a couple of options you have. Create the Foreign Key, and create an “On Update” trigger. Make use of the package below (needs to be installed in the db). http://tkyte

Anyway to create a SQL Server DDL trigger for “SELECT” statements?

喜夏-厌秋 提交于 2019-11-26 17:04:48
问题 I am dealing with some sensitive Accounting tables and I would like to audit any SELECT statement executed on the table or any views associated with them. I did not find any DDL Events on BOL (Books Online) that had anything to do with SELECT statement. And DML triggers are for INSERT , UPDATE and DELETE only. Is it possible to log who accesses table and views through SELECT statement? 回答1: You have 3 options: allow access via stored procedures if you want to log (and remove table rights)

Understanding QUOTED_IDENTIFIER

一曲冷凌霜 提交于 2019-11-26 17:01:49
问题 We just ran into a problem with one of our stored procs throwing an error; SELECT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER' I fixed it by modifiying the stored proc and setting the quoted identifier to ON. The thing is, I did this prior to the CREATE PROCEDURE call. For example; SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[InsertStuff] I would have thought that this affected the CREATE PROCEDURE statement, but wouldn't

What is DDL and DML? [closed]

孤者浪人 提交于 2019-11-26 15:35:44
I have heard the terms DDL and DML in reference to databases, but I don't understand what they are. What are they and how do they relate to SQL? DDL is Data Definition Language : it is used to define data structures . For example, with SQL, it would be instructions such as create table , alter table , ... DML is Data Manipulation Language : it is used to manipulate data itself . For example, with SQL, it would be instructions such as insert , update , delete , ... More information see here: MySQL What is DDL, DML and DCL? , the original is as follows: DDL DDL is short name of Data Definition

How to convert primary key from integer to serial?

别来无恙 提交于 2019-11-26 15:33:30
In a Postgres 9.3 table I have an integer as primary key with automatic sequence to increment, but I have reached the maximum for integer . How to convert it from integer to serial ? I tried: ALTER TABLE my_table ALTER COLUMN id SET DATA TYPE bigint; But the same does not work with the data type serial instead of bigint . Seems like I cannot convert to serial ? Erwin Brandstetter serial is a pseudo data type, not an actual data type. It's an integer underneath with some additional DDL commands executed automatically: Create a sequence (with matching name by default). Set the column NOT NULL

Safely rename tables using serial primary key columns

穿精又带淫゛_ 提交于 2019-11-26 15:29:05
I know that PostgreSQL tables that use a SERIAL primary key end up with an implicit index, sequence and constraint being created by PostgreSQL. The question is how to rename these implicit objects when the table is renamed. Below is my attempt at figuring this out with specific questions at the end. Given a table such as: CREATE TABLE foo ( pkey SERIAL PRIMARY KEY, value INTEGER ); Postgres outputs: NOTICE: CREATE TABLE will create implicit sequence "foo_pkey_seq" for serial column "foo.pkey" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo" Query

Can a number be used to name a MySQL table column?

蓝咒 提交于 2019-11-26 14:43:11
I have a table that has column names like 25, 50, 100, etc.. When trying to update the table I get an error, no matter how I do it UPDATE table SET '25'='100' WHERE id = '1' I have tried quoting and backticking every which way but without success. The error is always along the lines of: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''25'=100 WHERE id=1' at line 1 If I change the column name to twentyfive - I don't have a problem, but that's not what I want. Is it possible to use a number as a column name?

Is it possible to roll back CREATE TABLE and ALTER TABLE statements in major SQL databases?

橙三吉。 提交于 2019-11-26 12:53:51
I am working on a program that issues DDL. I would like to know whether CREATE TABLE and similar DDL can be rolled back in Postgres MySQL SQLite et al Describe how each database handles transactions with DDL. joeforker http://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis provides an overview of this issue from PostgreSQL's perspective. Is DDL transactional according to this document? PostgreSQL - yes MySQL - no; DDL causes an implicit commit Oracle Database 11g Release 2 and above - by default, no, but an alternative called edition-based redefinition exists