Questions tagged [alter-table]

The "ALTER TABLE" is a SQL statement that allows you to make schema changes to a database table (i.e. add, drop or alter columns from an existing table).

1118 questions
-1
votes
1 answer

MySQL Error Code 1452. Altering table to add foreign key

I removed the foreign key constraints to add data in, then I later altered the tables to add the foreign keys back in. However, with one particular table thats being altered, I keep getting an 1452 error code back. Data INSERT INTO…
user3654871
-1
votes
1 answer

SQL Server Management Studio Table Designer won't let me save Not NUll Column

I am trying to add a foreign relationship between two tables. When I add the FK column to my table and leave the check box for Allow Nulls blank, it wont let me save. Explaining the column does not allow nulls. How to get around this?
EB.
  • 2,627
  • 8
  • 35
  • 55
-1
votes
2 answers

Add auto-computed column in SQL

I'm trying to add an auto-computed column in my SQL table, which should be easy enough. However, I keep getting an error message saying there's something wrong with the syntax beginning with the word "AS" in the input below: ALTER TABLE users ADD…
h.vanoort
  • 13
  • 3
-1
votes
2 answers

MySQL Remove Field

Why I can't remove field from MySQL Database¿? mysql> describe Clients; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra …
aDoN
  • 1,877
  • 4
  • 39
  • 55
-1
votes
1 answer

Mysql UNIQUE INDEX on 3 fields when one field equals a value

I want to add a UNIQUE INDEX on 3 fields when one of the fields is True. ie equal to 1 UNIQUE INDEX pkg_box_delivered (package_id, box_id, delivered) WHERE delivered = 1; I need a Alter statement and how add it to a Create Table statement.
Avril
  • 25
  • 4
-1
votes
3 answers

T-SQL: modified CREATE TABLE script to ALTER TABLE script crashes

This script was generated from SQL Server Management Studio. Why am I getting this error and how can I fix the ALTER script? Note, that I changed the word "CREATE" to "ALTER". So I'm guessing the CREATE syntax is slightly different from the ALTER…
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
-1
votes
2 answers

I want to add a column, what is wrong with this MySQL query?

What is wrong with this query? ALTER TABLE KARGO ADD COLUMN test VARCHAR(100) NOT NULL DEFAULT t
ilhan
  • 8,700
  • 35
  • 117
  • 201
-1
votes
5 answers

Sql Column had no values

I have a sql table that I am trying to add a column from another table to. Only when I execute the alter table query it does not pull the values out of the table to match the column where I am trying to make the connection. For example I have…
developthestars
  • 185
  • 1
  • 12
  • 27
-2
votes
2 answers

Best practices to drop & update primary/unique keys on production without having a downtime

I am implementing data partitioning on mysql server(8.0). As a "must-have requirement of partitioning" I have to add my partition key as a primary key, which is created_at in my table. eg: alter table notifications drop primary key, add primary…
-2
votes
1 answer

Add a mandatory column of dates to an existing table

I want to add a new column called 'start_date' to a table called 'PROJECT', and I want this column to be mandatory. I have tried this: ALTER TABLE PROJECT ADD start_date date NOT NULL; This returns an ERROR: ERROR 1292 (22007): Incorrect date…
-2
votes
1 answer

What is the benefit of specifying a custom constraint index with primary key, foreign key or unique etc. in SQL?

I am trying to understand the index concept in SQL. It is clear to me why we use the index for columns but check these 2 variants of codes: ALTER TABLE Titles ADD CONSTRAINT Titles_pri_key PRIMARY KEY (title_id); and ALTER TABLE Titles PRIMARY KEY…
-2
votes
1 answer

Postgresql ALTER TABLE ADD KEY equivalent

What is the equivalent of this in postgresql ? -- -- Index for the table `Artist` -- ALTER TABLE `Artist` ADD PRIMARY KEY (`idArtist`), ADD UNIQUE KEY `name` (`name`,`firstName`); ADD KEY `idFilm` (`idFilm`);
Izaya
  • 1,270
  • 2
  • 13
  • 31
-2
votes
3 answers

Alter table and set default as current date

while creating a table I forgot to add a date of birth column. Is there a way to add a NOT NULL column to a table with default value being current date?
joel
  • 263
  • 1
  • 5
  • 16
-2
votes
2 answers

Alter table add column as SELECT

So I wanted to add new column to my table made from a select using two other tables. I tried a query like this: ALTER TABLE order ADD cost DECIMAL(5,2) AS (SELECT SUM(price*pieces) FROM book JOIN details ON id_book=book_id GROUP BY order_id); And I…
haniii98
  • 1
  • 1
  • 2
-2
votes
2 answers

ALTER TABLE query for foreign key constraint does not work

I'm a beginner and creating my own simple blockchain app for fun. The blockchain itself is fully functional. Now I'm trying to implement a database to store the data of the blockchain (right now I'm writing it to a .txt file). So I want to create…
1 2 3
74
75