mysql - dropping tables in sql -


hey new sql , having trouble dropping tables, sql have far is:

create table company ( cname       varchar(50)     not null, city        varchar(50)     not null,        street      varchar(50)     not null, bldgnum     decimal(4)      not null, email       varchar(320)    not null,  constraint comp_pkey primary key(cname), constraint comp_ckey1 unique(city, street, bldgnum), constraint comp_ckey2 unique(email) );   create table department ( cname       varchar(50)     not null, dname       varchar(50)     not null,  constraint dept_pkey primary key(cname, dname), constraint dept_fkey foreign key(cname) references company(cname) );   create table employee ( enumber             varchar(50)     not null, first_name          varchar(50)     not null,    last_name           varchar(50)     not null, date_of_brith       date                null, salary              decimal(7,2)    not null, cname               varchar(50)     not null, dname               varchar(50)     not null, employee_type       varchar(50)         null, manager_of_cname    varchar(50)         null, manager_of_dname    varchar(50)         null,  constraint emp_pkey primary key(enumber), constraint emp_fkey foreign(cname, dname) references department(cname, dname), constraint salary check (salary < 0) );   create table phone ( pnumber         decimal(10)         not null, cname           varchar(50)         not null,  constraint phn_pkey primary key(pnumber), constraint phn_fkey foreign key(cname) references company(cname) ); 

this has errors in believe want drop these tables error saying: cannot delete or update parent row: foreign key constraint fails. drop table sql:

drop table company; drop table department; drop table employee; drop table phone; 

sorry facepalms created while reading this, , thank appreciated.

you need start dropping child tables. here hierarcy have:

company --> department --> employee

you need first drop employee table, department , company table. point that, sql server cannot drop table while table being referenced table.

drop table employee; drop table department; drop table company; 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -