alter

Creating calculated fields in sql

ぐ巨炮叔叔 提交于 2019-12-05 21:52:15
This will seem rudimentary but I can't find a concise example online that matches up. I have three fields; m1 , m2 , and m3 . I need to create a column or field that is the average of them three. The calculated field would be titled employment. Would the following code be suffice? ALTER TABLE dbo.tablename ADD Employment AS Select ((m1+m2+m3)/3) Sample data m1 20 20 30 m2 15 17 25 m3 60 77 13 desired result. Name m1 m2 m3 Employment Auto body 20 20 30 23 Auto Parts 15 17 25 19 Auto Sales 60 77 13 50 You are very close, it's called Computed Column https://technet.microsoft.com/en-us/library

how to add column in a sqlite table in SWIFT

被刻印的时光 ゝ 提交于 2019-12-05 10:50:32
I try to add a column in a table with swift. my code : connect_db(); adddbfield("mynewfield","mytable"); . func connect_db() -> Bool { let sDBPath=<is correctly set>; if sqlite3_open(sDBPath, &db) != SQLITE_OK { println("Failed to open db") return false; }else{ return true; } } . func adddbfield(sFieldName:String, sTable:String) -> Bool { var bReturn:Bool=false; var sSQL="ALTER TABLE " + sTable + " ADD COLUMN " + sFieldName + " INTEGER DEFAULT -1"; var statement:COpaquePointer = nil if sqlite3_prepare_v2(db, sSQL, -1, &statement, nil) != SQLITE_OK { println("Failed to prepare statement") }else

Change column name without recreating the MySQL table

◇◆丶佛笑我妖孽 提交于 2019-12-05 09:11:57
Is there a way to rename a column on an InnoDB table without a major alter? The table is pretty big and I want to avoid major downtime. Renaming a column (with ALTER TABLE ... CHANGE COLUMN ) unfortunately requires MySQL to run a full table copy. Check out pt-online-schema-change . This helps you to make many types of ALTER changes to a table without locking the whole table for the duration of the ALTER. You can continue to read and write the original table while it's copying the data into the new table. Changes are captured and applied to the new table through triggers. Example: pt-online

HibernateJpaVendorAdapter's generateDdl doesn't alter tables

我怕爱的太早我们不能终老 提交于 2019-12-04 19:41:31
问题 I am developing a website using Spring+JPA+Hibernate. In the persistence configuration (JPA+Hibernate) I'm setting the HibernateJpaVendorAdapter's generateDdl attribute to true and in fact new entities correctly create the new table in the DB. Once the table has been created, though, if I add an attribute to the entity, I'm expecting the HibernateJpaVendorAdapter to alter the table and add the column as well. This is not happening and it's strange because in the Java AbstractJpaVendorAdapter

How to alter a MySQL table's foreign key using the command line

时光毁灭记忆、已成空白 提交于 2019-12-04 18:19:55
问题 How to alter an existing table in MySQL, setting foreign key to another table, using the command line? 回答1: You have to drop existing foreign key and create another one. For example like this: ALTER TABLE my_table DROP FOREIGN KEY my_key; ALTER TABLE my_table ADD CONSTRAINT my_key FOREIGN KEY ('some_id') REFERENCES some_new_table ('some_other_id') ON UPDATE CASCADE ON DELETE CASCADE; 回答2: Execute help alter table at mysql command prompt and the output is very much self explanatory. Look for

mysql alter int column to bigint with foreign keys

吃可爱长大的小学妹 提交于 2019-12-04 17:28:30
问题 I want to change the datatype of some primary-key columns in my database from INT to BIGINT. The following definition is a toy-example to illustrate the problem: CREATE TABLE IF NOT EXISTS `owner` ( `id` int(11) NOT NULL AUTO_INCREMENT, `thing_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `thing_id` (`thing_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; DROP TABLE IF EXISTS `thing`; CREATE TABLE IF NOT EXISTS `thing` ( `id` int(11) NOT NULL AUTO_INCREMENT

How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

浪子不回头ぞ 提交于 2019-12-04 07:27:15
问题 I would like to write a single SQL command to drop multiple columns from a single table in one ALTER TABLE statement. From MSDN's ALTER TABLE documentation... DROP { [CONSTRAINT] constraint_name | COLUMN column_name } Specifies that constraint_name or column_name is removed from the table. DROP COLUMN is not allowed if the compatibility level is 65 or earlier. Multiple columns and constraints can be listed. It says that mutliple columns can be listed in the the statement but the syntax doesn

How can I alter multiple tables at once in mysql?

对着背影说爱祢 提交于 2019-12-04 00:51:51
问题 I am trying to alter multiple tables and change the size of the username VARCHAR column to 999 as its current size is too small and now things are screwed up. How can I do this? I have tried the following and it worked for one table but when trying to update multiple table names it returned errors: ALTER TABLE `TABLE_NAME` CHANGE `username` VARCHAR( 999 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL 回答1: You can't do it with a single query. You need to query information_schema

HibernateJpaVendorAdapter's generateDdl doesn't alter tables

ぃ、小莉子 提交于 2019-12-03 12:46:05
I am developing a website using Spring+JPA+Hibernate. In the persistence configuration (JPA+Hibernate) I'm setting the HibernateJpaVendorAdapter's generateDdl attribute to true and in fact new entities correctly create the new table in the DB. Once the table has been created, though, if I add an attribute to the entity, I'm expecting the HibernateJpaVendorAdapter to alter the table and add the column as well. This is not happening and it's strange because in the Java AbstractJpaVendorAdapter's setGenerateDdl method documentation there is: "Set whether to generate DDL after the

How to alter a MySQL table's foreign key using the command line

早过忘川 提交于 2019-12-03 12:09:31
How to alter an existing table in MySQL, setting foreign key to another table, using the command line? You have to drop existing foreign key and create another one. For example like this: ALTER TABLE my_table DROP FOREIGN KEY my_key; ALTER TABLE my_table ADD CONSTRAINT my_key FOREIGN KEY ('some_id') REFERENCES some_new_table ('some_other_id') ON UPDATE CASCADE ON DELETE CASCADE; Execute help alter table at mysql command prompt and the output is very much self explanatory. Look for add constraint with foreign key clause and apply it on your table. mysql> help alter table Name: 'ALTER TABLE'