ddl

Transactional DDL workflow for MySQL

元气小坏坏 提交于 2019-12-05 11:13:41
问题 I was a little surprised to discover that DDL statements ( alter table , create index etc) implicitly commit the current transaction in MySQL. Coming from MS SQL Server, the ability to do database alterations in a transaction locally (that was then rolled back) was an important part of my workflow. For continuous integration, the rollback was used if the migration hiccuped for any reason, so that at least we did not leave the database in a half-migrated state. How do people solve these two

java学习笔记整理-数据库DDL,DML、Oracle函数

廉价感情. 提交于 2019-12-05 11:06:14
数据库可以分为两种 一.关系型数据库 1.Oracle甲骨文 11g 2.Mysql 甲骨文 5.5 5.7 3.sqlserver 微软 DB2 IBM 二.非关系型数据库:Nosql SQL: 对数据库进行增删改查 数据 Oracle: 远程连接:Linux-命令 SID-连接Oracle数据使用的唯一标识。crcl SQL语句:99标准 database DDL:数据定义语言-表 创建表:creat table user_LT(); 删表:drop table user_LT();//不可逆 查看表结构:desc user_LT; 修改字段增加字段:alter table user_lou add(); 删除字段:alter table user_lou drop(score); 修改字段类型//修改默认值:alter table user_LT MODIFY(className varchar(10)default’java1906’);//不能修改字段名 修改表名:alter table user_lou TO user_LT; 删除表中所有数据:truncate table user_LT;//不可逆 DML:数据操纵语言-数据(配合TCL) 添加数据:insert into user_lou values(1,‘rose’,‘java’,92.3,sysdate);

Is there a tool to generate a full database DDL for SQL Server? What about Postgres and MySQL?

流过昼夜 提交于 2019-12-05 10:56:10
问题 Using Toad for Oracle, I can generate full DDL files describing all tables, views, source code (procedures, functions, packages), sequences, and grants of an Oracle schema. A great feature is that it separates each DDL declaration into different files (a file for each object, be it a table, a procedure, a view, etc.) so I can write code and see the structure of the database without a DB connection. The other benefit of working with DDL files is that I don't have to connect to the database to

Renaming multiple columns in PostgreSQL

淺唱寂寞╮ 提交于 2019-12-05 09:01:39
My table has a bunch of columns in the following format: _settingA _settingB _settingB And I want to rename them simply to add a prefix as follows: _1_settingA _1_settingB _1_settingC What is the quickest / most efficient way to achieve this? EDIT: I should add that I have a lot more than three columns to rename in this way. If I had just three, I'd just do it manually one by one. And thanks for the downvote whoever you are. Gabriel's Messanger There's no single command aproach. Obviously you could type multiple comands for RENAME by your self, but let me intoduce some improvement:) As I said

How do you add a computed column to a Table?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 08:20:26
问题 How can I add a computed column to a table that already exists? S.O. has Computed Column Help - TSQL but no information about adding them. 回答1: The syntax I was looking for is: alter table TABLE_NAME add [column_name] as (**COLUMN-SQL**) 来源: https://stackoverflow.com/questions/11058387/how-do-you-add-a-computed-column-to-a-table

T-SQL Scripts to copy all table constraints

扶醉桌前 提交于 2019-12-05 03:25:44
I have created many tables on my local database and moved them to production database. Now I am working on fine tuning the database and created many constraints on my local database tables such as PK, FK, Default Values, Indexes etc. etc. Now I would like to copy only these constraints to production database. Is there a way to do it? Please note that my production database tables already populated with some data. So I can’t drop and recreate them. If you don't want to buy any tools (which are totally worth their price, BTW), you can always interrogate the system catalog views, and extract the

Why is truncate a DDL statement?

我是研究僧i 提交于 2019-12-05 03:05:26
The table structure remains same after truncate statement and only records get deleted (with auto commit). Then what is the reason that truncate is a DDL statement ? I'd add here some explanation: By default, when truncating a table , you are not just removing rows, you are implicitly telling Oracle Database to also perform the following tasks: Deallocates all space used by the removed rows except that specified by the MINEXTENTS storage parameter Sets the NEXT storage parameter to the size of the last extent removed from the segment by the truncation process So, it changes the storage

How to change a dataype CLOB TO VARCHAR2(sql)

荒凉一梦 提交于 2019-12-05 02:23:53
Table: customers ID NAME DATATYPE NUMBER VARCHAR2(100) CLOB I want to change the DATA column from CLOB to `VARCHAR2(1000) I have try ALTER TABLE customers MODIFY DATA VARCHAR2 (1000) also ALTER TABLE customers MODIFY (DATA VARCHAR2 (1000)) also alter table customers modify (data VARCHAR2(4000)) those normally works if the datatype is not a clob but I am getting a ORA-22859 because I am using oracle toad/apex. Rahul Tripathi You may try this: Add a new column as varchar2 alter table my_table add (new_column varchar2(1000)); UPDATE CLOB name to varchar2 column; update my_table set new_column

Drop column and all dependent objects using data definition language

梦想与她 提交于 2019-12-05 00:26:18
问题 I need to remove a column from a table, but when I try to remove it: The object 'object_name' is dependent on column 'column_name'. ALTER TABLE DROP COLUMN column_name failed because one or more objects access this column. I can look for the dependency in the system tables and remove it manually, but I need to do a migration (using SQL DDL) so all others members of the team just do the update, run the migration and don´t have to mess up up system objects. 回答1: Try this code: Declare

Mysql DDL语句之视图

本小妞迷上赌 提交于 2019-12-04 21:02:40
Mysql 视图是一个虚拟表,内容由 select 查询语句定义, 同真实的表数据一致, 但是视图并不在数据库中以存储的数据值形式存在。 试图引用自定义查询表的字段, 并且在引用试图时动态生成, 对其所引用的基础表来说 Mysql 视图的作用类似于筛选。 创建视图 创建视图 查看视图 修改视图 删除视图 toc 定义视图的筛选可以来自当前或其它数据库的一个或多个表,或者其它视图。 视图查询没有任何限制,通过它们进行数据修改时的限制也很少。 视图是存储在数据库中的 SQL 查询语句,它主要出于两种原因: 安全原因, 视图可以隐藏一些敏感的信息。 简化查询, 使复杂的查询易于理解和使用 创建视图 创建单表视图环境准备 ## 创建表 mysql> use test; mysql> create table t2( id int primary key AUTO_INCREMENT not null, name varchar(30) not null, sex enum('man','gril') default 'man' not null, time date not null, post varchar(50) not null, job varchar(100), salary double(15,2) not null, dep_id int ); ## 插入数据 mysql>