ddl

Alter Table Add Column Syntax

微笑、不失礼 提交于 2019-11-30 10:22:55
问题 I'm trying to programmatically add an identity column to a table Employees. Not sure what I'm doing wrong with my syntax. ALTER TABLE Employees ADD COLUMN EmployeeID int NOT NULL IDENTITY (1, 1) ALTER TABLE Employees ADD CONSTRAINT PK_Employees PRIMARY KEY CLUSTERED ( EmployeeID ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] What am I doing wrong? I tried to export the script, but SQL Mgmt Studio does a whole Temp Table

How do I get alembic to emit custom DDL on after_create?

ⅰ亾dé卋堺 提交于 2019-11-30 09:02:35
I've got a couple of custom DDL statements that I want to run after create table: update_function = DDL(""" CREATE OR REPLACE FUNCTION update_timestamp() RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = now(); RETURN NEW; END; $$ language 'pgplsql'; """) update_trigger = DDL(""" CREATE TRIGGER update %(table)s_timestamp BEFORE UPDATE ON %(table)s FOR EACH ROW EXECUTE PROCEDURE update_timestamp(); """) And I've attached them like this: event.listen(Session.__table__, 'after_create', update_function) event.listen(Session.__table__, 'after_create', update_trigger) When I do create_all , I get the SQL

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

柔情痞子 提交于 2019-11-30 08:53:31
问题 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

mysql DDL,DML

故事扮演 提交于 2019-11-30 06:13:53
mysql 数据库DDL,DML 1 DDL 语法 DDL是数据定义语言的缩写 对数据库 表 进行操作 create drop alter 创建 删除 修改 1创建数据库 create datebase dbname; ① 使用数据库 use dbname ②查看所有数据库 show datebases; ③查看数据库详细信息 show create database dbname ; 2删除数据库 drop datebase dbname; 3 创建表 create table tablename ( clo_name clo_type, ... ); 4 删除表 drop table tablename; 5查看表详细信息 方法① desc tabelname ; 方法② show create tablename \G; 6修改表属性 ①修改表名 rename tabename to newtablename ; ②修改表的字段类型 alter tabel tablename modify clo_name clo_type ③修改表的字段名,和同时修改表的字段属性 alter table tablename change clo_name clo_new_name clo_type #注意 change modify 都可以修改字段类型,但是change 要写两次字段名

Can I configure Hibernate to create separate sequence for each table by default?

空扰寡人 提交于 2019-11-30 05:47:14
问题 Hibernate by default creates a globel sequence which is used to generate ids for all tables, (in the case for PostgreSQL) which scales very bad IMHO. Though I can specify for each entity type which sequence to use, I don't like to do it. I don't like to explicit name the sequence and force to use sequence as the generator strategy, because I want hibernate generate DDL for databases which may not support sequence at all. The single global sequence also make it impossible to use 32-bit int as

Test Column exists, Add Column, and Update Column

不问归期 提交于 2019-11-30 04:11:44
I'm trying to write a SQL Server database update script. I want to test for the existence of a column in a table, then if it doesn't exist add the column with a default value, and finally update that column based on the current value of a different column in the same table. I want this script to be runnable multiple times, the first time updating the table and on subsequent runs the script should be ignored. My script currently looks like the following: IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'PurchaseOrder' AND COLUMN_NAME = 'IsDownloadable') BEGIN ALTER

MySQL 5.7使用xtabackup报错解决

馋奶兔 提交于 2019-11-29 19:22:29
报错信息: InnoDB: An optimized (without redo logging) DDLoperation has been performed. All modified pages may not have been flushed to the disk yet. 为了解决这个错误,percona新加了三个参数xtrabackup --lock-ddl, xtrabackup --lock-ddl-timeout, xtrabackup --lock-ddl-per-table。 MySQL5.7在记录redo log时会跳过某些DDL。在MySQL5.7当中,创建索引分为三个阶段 1:扫描clustered index,生成索引项到sort buffer当中,当sort buffer满了的时候,会写入到临时文件当中。 2:多个线程对临时文件或者sort buffer中的索引项进行排序 3:排序完成后插入到 B-tree当中。 在此之前,MySQL创建索引的时候会调用insert APIs逐条进行 B-tree的插入,这种插入方式会打开 B-tree游标,找到位置,乐观插入。如果要插入的 B-tree节点page页满了,就会拆分或者合并 B-tree的page页,我们称之为悲观插入。这样创建索引就会引起不断分裂和合并,并且还有查找插入位置,代价会比较昂贵。

How to delete a column from a table in MySQL

和自甴很熟 提交于 2019-11-29 19:02:39
Given the table created using: CREATE TABLE tbl_Country ( CountryId INT NOT NULL AUTO_INCREMENT, IsDeleted bit, PRIMARY KEY (CountryId) ) How can I delete the column IsDeleted ? ALTER TABLE tbl_Country DROP COLUMN IsDeleted; Here's a working example. Note that the COLUMN keyword is optional, as MySQL will accept just DROP IsDeleted . Also, to drop multiple columns, you have to separate them by commas and include the DROP for each one. ALTER TABLE tbl_Country DROP COLUMN IsDeleted, DROP COLUMN CountryName; This allows you to DROP , ADD and ALTER multiple columns on the same table in the one

Create a temporary table in MySQL with an index from a select

懵懂的女人 提交于 2019-11-29 18:48:26
I have a stored function where I use temporary tables. For performance reasons, I need an index in that table. Unfortunately, I cannot use ALTER TABLE because this causes an implicit commit. Therefore I'm looking for the syntax to add the INDEX for tempid during creation. Can anyone be of help? CREATE TEMPORARY TABLE tmpLivecheck ( tmpid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY ) SELECT * FROM tblLivecheck_copy WHERE tblLivecheck_copy.devId = did; I wrestled quite a while with the proper syntax for CREATE TEMPORARY TABLE SELECT. Having figured out a few things, I wanted to share the answers

Hive的数据类型与DML和DDL

假如想象 提交于 2019-11-29 18:27:11
Hive 数据类型: 基本数据类型: Hive数据类型 Java数据类型 长度 例子 TINYINT byte 1byte有符号整数 20 SMALINT short 2byte有符号整数 20 INT int 4byte有符号整数 20 BIGINT long 8byte有符号整数 20 BOOLEAN boolean 布尔类型,true或者false TRUE FALSE FLOAT float 单精度浮点数 3.14159 DOUBLE double 双精度浮点数 3.14159 STRING string 字符系列。可以指定字符集。可以使用单引号或者双引号。 ‘now is the time’ “for all good men” TIMESTAMP 时间类型 BINARY 字节数组 ​ 对于 Hive 的 String 类型相当于数据库的 varchar 类型,该类型是一个可变的字符串,不过它不能。其中最多能存储多少个字符,理论上它可以存储2GB的字符数。 集合数据类型: 数据类型 描述 语法示例 STRUCT 和c语言中的struct类似,都可以通过“点”符号访问元素内容。例如,如果某个列的数据类型是STRUCT{first STRING, last STRING},那么第1个元素可以通过字段.first来引用。 struct() MAP MAP是一组键-值对元组集合