ddl

DDL 语句

纵然是瞬间 提交于 2019-11-26 12:51:17
DDL 是数据定义语言的缩写,简单来说, 就是对数据库内部的对象 进行创建、删除、修改的操作语言。 它和 DML 语言的最大区别是 DML 只是对表内部数据的操作,而不涉及到表的定义、结构的修改,更不会涉及到其他对象。DDL 语句更多的被数据库管理员(DBA)所使用, 一般的开发人员很少使用。 下面通过一些例子来介绍 MySQL 中常用 DDL 语句的使用方法。 1.创建数据库 启动 MySQL 服务之后,输入以下命令连接到 MySQL 服务器: [mysql@db3 ~]$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7344941 to server version: 5.1.9-beta-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> 在以上命令行中,mysql 代表客户端命令,-u 后面跟连接的数据库用户,-p 表示需要输入密码。如果数据库设置正常,并输入正确的密码,将看到上面一段欢迎界面和一个 mysql>提示符。在欢迎界面中介绍了以下几部分内容。 命令的结束符: 用;或者\g 结束。

Delete column from SQLite table

六月ゝ 毕业季﹏ 提交于 2019-11-26 12:07:01
I have a problem: I need to delete a column from my SQLite database. I wrote this query alter table table_name drop column column_name but it does not work. Please help me. MeBigFatGuy From: http://www.sqlite.org/faq.html : (11) How do I add or delete columns from an existing table in SQLite. SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table,

How do you like your primary keys? [closed]

会有一股神秘感。 提交于 2019-11-26 11:34:49
In a fairly animated discussion in my team I was made to think what most people like as primary keys. We had the following groups- Int/ BigInt which autoincrement are good enough primary keys. There should be at least 3 columns that make up the primary key. Id, GUID and human readable row identifiers all should be treated differently. What's the best approach for PKs? It would be awesome if you could justify your opinion. Is there a better approach that the above? EDIT: Anyone has a simple sample/algorithm to generate human readable identifiers for rows that scales well? If you're going to be

【Oracle】Oracle DML,DDL,DCL区别【20140612】

心已入冬 提交于 2019-11-26 11:07:35
总体解释: 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 详细解释: 一、DDL is Data Definition Language statements. Some examples:数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 1.CREATE - to create objects in the database 创建 2.ALTER - alters the structure of the database 修改 3.DROP - delete objects

Using ALTER to drop a column if it exists in MySQL

折月煮酒 提交于 2019-11-26 09:32:37
问题 How can ALTER be used to drop a column in a MySQL table if that column exists? I know I can use ALTER TABLE my_table DROP COLUMN my_column , but that will throw an error if my_column does not exist. Is there alternative syntax for dropping the column conditionally? I\'m using MySQL version 4.0.18. 回答1: For MySQL, there is none: MySQL Feature Request. Allowing this is arguably a really bad idea, anyway: IF EXISTS indicates that you're running destructive operations on a database with (to you)

Why use multiple columns as primary keys (composite primary key)

做~自己de王妃 提交于 2019-11-26 09:16:17
问题 This example is taken from w3schools. CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) ) My understanding is that both columns together ( P_Id and LastName ) represent a primary key for the table Persons . Is this correct? Why would someone want to use multiple columns as primary keys instead of a single column? How many columns can be used together as a

Is it possible to run multiple DDL statements inside a transaction (within SQL Server)?

半城伤御伤魂 提交于 2019-11-26 08:34:56
问题 I\'m wondering if it is possible to run multiple DDL statements inside a transaction. I\'m specially interested on SQL Server, even though answers with other databases (Oracle, PostgreSQL at least) could also be interesting. I\'ve been doing some \"CREATE TABLE\" and \"CREATE VIEW\" for the created table inside a transaction and there seems to be some inconsistencies and I\'m wondering if the DDLs shouldn\'t be done inside the transaction... I could probably move the DDL outside the

MySQL: ALTER TABLE if column not exists

孤者浪人 提交于 2019-11-26 08:05:48
问题 I have this code: ALTER TABLE `settings` ADD COLUMN `multi_user` TINYINT(1) NOT NULL DEFAULT 1 And I want to alter this table only if this column doesn\'t exist. I\'m trying a lot of different ways, but nothing works: ALTER TABLE `settings` ADD COLUMN IF NOT EXISTS `multi_user` TINYINT(1) NOT NULL DEFAULT 1 With procedure: DELIMITER $$ CREATE PROCEDURE Alter_Table() BEGIN DECLARE _count INT; SET _count = ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = \'settings\' AND

Adding multiple columns AFTER a specific column in MySQL

左心房为你撑大大i 提交于 2019-11-26 06:55:22
问题 I need to add multiple columns to a table but position the columns after a column called lastname . I have tried this: ALTER TABLE `users` ADD COLUMN ( `count` smallint(6) NOT NULL, `log` varchar(12) NOT NULL, `status` int(10) unsigned NOT NULL ) AFTER `lastname`; I get this error: 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 \') AFTER lastname \' at line 7 How can I use AFTER in a query like this? 回答1:

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

你。 提交于 2019-11-26 06:25:21
问题 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