Questions tagged [alter]

'alter' is a SQL keyword used to change or modify the table structure or the records in a table.

835 questions
42
votes
1 answer

How to change the primary key to be non-clustered?

Part-time reluctant DBA here. I want to change an existing primary key index from clustered to non-clustered. And the syntax is escaping me. This is how it's scripted out right now. ALTER TABLE [dbo].[Config] WITH NOCHECK ADD CONSTRAINT…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
42
votes
5 answers

Difference between Alter and Update SQL

I am busy studying MySQL and I understand that update is used to update a record or row in a table. So what does alter do that is so different? Seems like they are the same. Thanks, any help will be appreciated.
Artic-M00n
  • 533
  • 2
  • 8
  • 15
41
votes
6 answers

error: ALTER TYPE ... ADD cannot run inside a transaction block

I am trying to add new type value to my existing types in PostgreSQL. But I get the following error error: ALTER TYPE ... ADD cannot run inside a transaction block The query I used to add a new value to the type is ALTER TYPE public.request_type…
Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162
41
votes
4 answers

syntax error at or near "-" in PostgreSQL

I'm trying to run a query to update the user password using. alter user dell-sys with password 'Pass@133'; But because of - it's giving me error like, ERROR: syntax error at or near "-" LINE 1: alter user dell-sys with password 'Pass@133'; …
OpenCurious
  • 2,916
  • 5
  • 22
  • 25
37
votes
3 answers

How to rename a column name in maria DB

I am new to SQL, I was trying to change column name in my database's table. I am using 'xampp' with 'maria DB' (OS - Ubuntu 18.04) I tried all of the followings: ALTER TABLE subject RENAME COLUMN course_number TO course_id; ALTER TABLE subject…
Kaveen Hyacinth
  • 495
  • 1
  • 4
  • 10
37
votes
4 answers

Hive Alter table change Column Name

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) ??
user2978621
  • 803
  • 2
  • 11
  • 20
34
votes
2 answers

What happens if you kill a long-running alter query?

What happens if you kill a long-running alter query? Will the alter query simply revert? How long could that take (as a proportion of the time it has already been running)? What if that query is being replicated onto another server? Will killing the…
B T
  • 57,525
  • 34
  • 189
  • 207
33
votes
5 answers

Adding a Boolean column into an existing table

I'm trying to add a boolean column into an existing table alter table chatuser add activerecord bool; alter table chatuser add activerecord boolean; where activerecord is my boolean column Neither of these queries are working. How can I add a…
uday gowda
  • 609
  • 3
  • 10
  • 16
31
votes
2 answers

alter composite primary key in cassandra CQL 3.0

I'm in a situation where I need to change the the composite primary key as follows: Old Primary Key: (id, source, attribute_name, updated_at); New Primary Key I want: (source, id, attribute_name, updated_at); I issued the following (mysql like)…
aroyc
  • 890
  • 2
  • 13
  • 26
28
votes
3 answers

Alter column set not null fails

Consider the following table with approximately 10M rows CREATE TABLE user ( id bigint NOT NULL, ... CONSTRAINT user_pk PRIMARY KEY (id) ) WITH ( OIDS=FALSE ) Then i applied the following alter ALTER TABLE USER ADD COLUMN BUSINESS_ID …
dimcookies
  • 1,930
  • 7
  • 31
  • 37
27
votes
4 answers

How to add new column in existing View in SQL-Server 2014 using Alter

I have created a view that is based on another view and a table. I want to add new column of type varchar. I did like below, But getting syntax error? I am new to SQL, So,could not understand ALTER VIEW [dbo].[MyView] ADD New_Col varchar(10) null…
SPBeginer
  • 733
  • 3
  • 14
  • 29
27
votes
2 answers

How to add a column to a table from another table in Mysql?

I have two tables table1 table2 Tabel1 contains 2 columns id Name Tabel2 contains 2 columns id Age A want to add age column from table2 to table1 (WHERE table1.id = table2.id) Then table1 should contains 3 columns id Name Age
Codesl
  • 547
  • 2
  • 5
  • 10
27
votes
4 answers

Alter SQL table - allow NULL column value

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…
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
26
votes
2 answers

What is the equivalent of 'CREATE TABLE ... LIKE ..." in SQL Server

I am working with SQL Server (I am a SQL Server noob) and trying to alter a table. I want to CREATE TABLE LIKE to safely store data while I drop keys and constraints and all the other rigamorole that SQL Server seems to require when altering on the…
Ichorus
  • 4,567
  • 6
  • 38
  • 46
21
votes
2 answers

Adding new enum column to an existing table

I'm trying to add a gender column to my table with this query: ALTER TABLE QRCodeUser ADD gender CHAR(1) enum('M','F') NOT NULL; I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL…
max85
  • 245
  • 1
  • 3
  • 8
1
2
3
55 56