ddl

DML,DDL,DCL的区别

夙愿已清 提交于 2019-12-04 12:18:56
DML(Data Manipulation Language): 它们是SELECT、UPDATE、INSERT、DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言 DDL(Data Definition Language): DDL比DML要多,主要的命令有CREATE、ALTER、DROP等,DDL主要是用在定义或改变表(TABLE)的结构,数据类型,表之间的链接和约束等初始化工作上,他们大多在建立表时使用 DCL(Data Control Language): 是数据库控制功能。是用来设置或更改数据库用户或角色权限的语句,包括(grant,deny,revoke等)语句。在默认状态下,只有sysadmin,dbcreator,db_owner或db_securityadmin等人员才有权力执行DCL 来源: https://www.cnblogs.com/mobies/p/11863616.html

Cannot cast type numeric to boolean

一笑奈何 提交于 2019-12-04 08:50:19
ALTER TABLE products ALTER COLUMN power_price DROP DEFAULT; ALTER TABLE products ALTER COLUMN power_price TYPE bool USING (power_price::boolean); ALTER TABLE products ALTER COLUMN power_price SET NOT NULL; ALTER TABLE products ALTER COLUMN power_price SET DEFAULT false; Postgres gives me this error: Query failed: ERROR: cannot cast type numeric to boolean Use: ALTER TABLE products ALTER power_price TYPE bool USING (power_price::int::bool); There is no direct cast defined between numeric and boolean . You can use integer as middle-ground. text would be another candidate for middle ground, since

In MySQL, with FKs what's “CONSTRAINT” do?

删除回忆录丶 提交于 2019-12-04 06:15:18
I've looked at the MySQL 5.1 docs, and still can't figured this out -- that being I noticed a difference between the code I input into MySQL and output code by the system. What is the difference between the code sample 01 and 02, meaning 02 has added CONSTRAINT before FOREIGN KEY -- why, and what's it do? CODE_SAMPLE_01: FOREIGN KEY (TABLE_02_nID_FK__TABLE_01_sID_PK) REFERENCES TABLE_01(TABLE_01_sID_PK), CONTEXT: CREATE TABLE `TABLE_02` ( `TABLE_02_sID_PK` int(8) NOT NULL, `TABLE_02_nID_FK__TABLE_01_sID_PK` int(8) NOT NULL, `TABLE_02_cID` int(8) NOT NULL, `TABLE_02_data01` varchar(128) default

Setting the comment of a column to that of another column in Postgresql

大憨熊 提交于 2019-12-04 03:15:47
问题 Suppose I create a table in Postgresql with a comment on a column: create table t1 ( c1 varchar(10) ); comment on column t1.c1 is 'foo'; Some time later, I decide to add another column: alter table t1 add column c2 varchar(20); I want to look up the comment contents of the first column, and associate with the new column: select comment_text from (what?) where table_name = 't1' and column_name = 'c1' The (what?) is going to be a system table, but after having looked around in pgAdmin and

Postgres database create if not exists [duplicate]

雨燕双飞 提交于 2019-12-04 00:54:40
This question already has an answer here: Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL? 7 answers Is there an analog to CREATE TABLE IF NOT EXISTS for creating databases? Background: I am writing a script to automatically set up the schema in PostgreSQL on an unknown system. I am not sure if the database (or even part of the schema) was already deployed, so I want to structure my code to not fail (or ideally even show errors) if some of the structure already exists. I want to differentiate the errors that prevent me from creating a database (so abort future schema changes since they

Transactional DDL workflow for MySQL

夙愿已清 提交于 2019-12-04 00:49: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 problems when using MySQL with migrations and continuous integration? DDL statements cause an implicit

Forcing Management Studio to use ALTER TABLE instead of DROP/CREATE

谁说我不能喝 提交于 2019-12-04 00:25:38
问题 I'm wondering if is there a way to force MSSQL Management Studio to produce a script like this: ALTER TABLE Mytable ADD MyCol bit NOT NULL CONSTRAINT MyColDefault DEFAULT 0 WITH VALUES ALTER TABLE [dbo].Mytable ALTER COLUMN MyCol2 int NULL GO when I alter a very simple property of a column on a table. If I do this in the designer and ask for the produced script, the script doesn't do such simple tasks, but instead copies all the data in a tmp table, drops the original table, renames the tmp

Do statistics referencing a column prevent that column from being dropped?

别说谁变了你拦得住时间么 提交于 2019-12-04 00:13:09
I'm trying a very simple drop column statement: alter table MyTable drop column MyColumn and receiving several errors along the lines of Msg 5074, Level 16, State 1, Line 1 The statistics '_dta_stat_1268251623_3_2' is dependent on column 'MyColumn'. followed ultimately by Msg 4922, Level 16, State 9, Line 1 ALTER TABLE DROP COLUMN MyColumn failed because one or more objects access this column. I didn't think statistics prevent a column from being dropped. Do they? If so, since these are apparently auto-created statistics I can't depend on the names being the same across multiple copies of the

How can I create a unique index in Oracle but ignore nulls?

二次信任 提交于 2019-12-03 23:21:10
问题 I am trying to create a unique constraint on two fields in a table. However, there is a high likelihood that one will be null. I only require that they be unique if both are not null ( name will never be null). create unique index "name_and_email" on user(name, email); Ignore the semantics of the table and field names and whether that makes sense - I just made some up. Is there a way to create a unique constraint on these fields that will enforce uniqueness for two not null values, but ignore

How to alter “REFERENCES” in PostgreSQL?

为君一笑 提交于 2019-12-03 22:38:29
How can I alter the reference to a table in PostgreSQL when the table name has been changed? Say I have: CREATE TABLE example1 ( id serial NOT NULL PRIMARY KEY, name varchar(100) ); CREATE TABLE example2 ( id serial NOT NULL PRIMARY KEY, example1fk integer REFERENCES example1 (id) DEFERRABLE INITIALLY DEFERRED ); Later I do: ALTER TABLE example1 RENAME TO example3; How to change the definition of the foreign key constraint? example1fk integer REFERENCES example1 (id) DEFERRABLE INITIALLY DEFERRED, Internal dependencies between tables and / or other objects are never bound to the object name.