alter

mysql alter int column to bigint with foreign keys

二次信任 提交于 2019-12-03 11:05:11
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, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

Alter column length in Schema builder?

≯℡__Kan透↙ 提交于 2019-12-03 08:40:46
问题 I have two fields i need to increment the character limit on. I're read through the documentation and to my surprise i found no option for it. Is it possible to do? If not, how should i go about solving this? I could drop the column and re-create it with the correct properties, but i don't want to loose any data in the database. 回答1: Use Raw Queries: /** * Make changes to the database. * * @return void */ public function up() { DB::query('ALTER TABLE mytable MODIFY mycolumn VARCHAR(new-length

Trying to modify a constraint in PostgreSQL

*爱你&永不变心* 提交于 2019-12-03 06:28:16
问题 I have checked the documentation provided by Oracle and found a way to modify a constraint without dropping the table. Problem is, it errors out at modify as it does not recognize the keyword. Using EMS SQL Manager for PostgreSQL. Alter table public.public_insurer_credit MODIFY CONSTRAINT public_insurer_credit_fk1 deferrable, initially deferred; I was able to work around it by dropping the constraint using : ALTER TABLE "public"."public_insurer_credit" DROP CONSTRAINT "public_insurer_credit

SQL Server: how to write an alter index statement to add a column to the unique index?

穿精又带淫゛_ 提交于 2019-12-03 06:13:26
问题 I have a UNIQUE, NON CLUSTERED index on a table that is currently using 4 columns for the index. I want to create an alter script that can merely add another column to this index. The new column type is varchar . The database is SQL Server 2005. Thanks in advance. 回答1: You cannot alter an index - all you can do is drop the old index ( DROP INDEX (indexname) ON (tablename) ) re-create the new index with the additional column in it: CREATE UNIQUE NONCLUSTERED INDEX (indexname) ON dbo

Hive Alter table change Column Name

随声附和 提交于 2019-12-03 03:42:02
问题 I am trying to rename a columnName in Hive. Is there a way to rename column name in Hive . tableA (column1 ,_c1,_c2) to tableA(column1,column2,column3) ?? 回答1: Change Column Name/Type/Position/Comment: ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name] Example: CREATE TABLE test_change (a int, b int, c int); // will change column a's name to a1 ALTER TABLE test_change CHANGE a a1 INT; 回答2: Command works only if "use"

Alter column length in Schema builder?

爱⌒轻易说出口 提交于 2019-12-02 22:28:43
I have two fields i need to increment the character limit on. I're read through the documentation and to my surprise i found no option for it. Is it possible to do? If not, how should i go about solving this? I could drop the column and re-create it with the correct properties, but i don't want to loose any data in the database. Use Raw Queries : /** * Make changes to the database. * * @return void */ public function up() { DB::query('ALTER TABLE mytable MODIFY mycolumn VARCHAR(new-length)'); } /** * Revert the changes to the database. * * @return void */ public function down() { DB::query(

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

前提是你 提交于 2019-12-02 14:02:08
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't show an optional comma or anything that would even hint at the syntax. How should I write my SQL to

Create table with COUNT ms-access

给你一囗甜甜゛ 提交于 2019-12-02 12:26:39
I have a database and I want to create a table with COUNT function in it. Is it possible ? I have 3 existing tables: Member Feedback Attendance In Feedback table, 2 columns Class_ID, Likes (Class_ID link with the attendance, as each member attend 1 class eg. class 1,2,3,etc. and Likes is for the number of people like the class). In Attendance table, 3 columns: Class_ID Member_ID Non_member_name Now I want to alter Feedback table to add 2 new columns. One to count the number of people attend the class, e.g if there is 4 people attend class 1,there would be 4 rows of Class_ID=1. Two to count the

MySQL - How to modify column default value?

折月煮酒 提交于 2019-12-01 02:45:14
问题 How do I change my column's default value from None to something else? For example, I want my dates to have a default value of 0000-00-00 if I don't specify one when I create the row. I understand this in phpMyAdmin, but I'm not sure how to do it via command prompt. I also understand how to do this when adding a column. But all of my columns are made and have data in some of them. ALTER TABLE table1 ADD COLUMN foo INT DEFAULT 0; From searching, I found this line, but I'm not sure if that's

Alter SQL table - allow NULL column value

不问归期 提交于 2019-11-30 17:13:01
Initially, the table "MyTable" has been defined in the following way: CREATE TABLE IF NOT EXISTS `MyTable` ( `Col1` smallint(6) NOT NULL AUTO_INCREMENT, `Col2` smallint(6) DEFAULT NULL, `Col3` varchar(20) NOT NULL, ); How to update it in such a way that the column "Col 3" would be allowed to be NULL? Tschareck The following MySQL statement should modify your column to accept NULLs. ALTER TABLE `MyTable` ALTER COLUMN `Col3` varchar(20) DEFAULT NULL ALTER TABLE MyTable MODIFY Col3 varchar(20) NULL; 来源: https://stackoverflow.com/questions/10597982/alter-sql-table-allow-null-column-value