Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql modify foreign key

-- 2 Step process
ALTER TABLE tbl_name_1 DROP FOREIGN KEY fk_name;
ALTER TABLE tbl_name_1 ADD FOREIGN KEY fk_name(fk_col)
            REFERENCES tbl_name_2(pk_name) ON DELETE RESTRICT;


-- Use to find the name of the FOREIGN KEY 
SHOW CREATE TABLE tbl_name;
Comment

alter table add foreign key mysql

ALTER TABLE orders
ADD 
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; 
Comment

alter table add column and foreign key mysql

ALTER TABLE database.table
  ADD COLUMN columnname INT DEFAULT(1),
  ADD FOREIGN KEY fk_name(fk_column) REFERENCES reftable(refcolumn) ON DELETE CASCADE;
Comment

mysql alter add foreign key

ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);
// I'm Horrible Hyena
Comment

mysql alter add foreign key

ALTER TABLE ordenes ADD ticket VARCHAR(50) NOT NULL;
ALTER TABLE ordenes ADD CONSTRAINT fk_ticket FOREIGN KEY (ticket) REFERENCES tickets(ticket);
Comment

add column mysql with foreign key

ALTER TABLE `TABLE_NAME`
ADD COLUMN `COLUMN_NAME` BIGINT(20) UNSIGNED NULL DEFAULT NULL AFTER `AFTER_COLUMN_NAME`, 
ADD FOREIGN KEY `FOREIGN_RELATION_NAME`(`COLUMN_NAME`) REFERENCES `FOREIGN_TABLE`(`FOREIGN_COLUMN`)  ON UPDATE SET NULL ON DELETE SET NULL
Comment

PREVIOUS NEXT
Code Example
Sql :: install mysql 5.7 
Sql :: sql date format 
Sql :: unsigned int in mysql 
Sql :: sql pad left 0 
Sql :: events mysql 
Sql :: sql insert multiple rows 
Sql :: sql select duplicates based on two columns 
Sql :: left join in codeigniter query builder 
Sql :: sql find duplicate records in two tables 
Sql :: mysql select true or false 
Sql :: restroe pg_dump example 
Sql :: check if has alpha characters sql 
Sql :: oracle apex view logs 
Sql :: get records in sql according to month name and count 
Sql :: psql create user 
Sql :: restore backup to new database sql server 
Sql :: oracle temporary table 
Sql :: create user mariadb 
Sql :: postgresql import a database of gzip 
Sql :: sql get inserted primary key 
Sql :: alter column set not null to null postgres 
Sql :: sql function to add all values round of 2 decimal places 
Sql :: mysql run sql file 
Sql :: AND OR NOT operators sql 
Sql :: change password postgres pgserver 
Sql :: postgres update single column 
Sql :: sql database connectivity 
Sql :: sql server select furst day of current year 
Sql :: complete date is 1 year or not sql server 
Sql :: mysql max 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =