0

File

drop database if exists contacts

create database contacts;

use contacts;

create table names
(
    ID mediumint not null auto_increment primary key,
    firstName varchar(20),
    lastName varchar(20)
);

create table addresses
(
    ID mediumint not null auto_increment primary key,
    nameID mediumint not null,
    addr1 varchar(30),
    addr2 varchar(30),
    city varchar(30),
    state varchar(10),
    postal_code varchar(10)
);

insert into names (firstName, lastName)
values ('John', 'Doe'), ('Mary', 'Smith'), ('Bill', 'Jones'), ('Dave', 'White'), ('Jane', 'Tate');

insert into addresses (nameID, addr1, addr2, city, state, postal_code)
select ID, '123 4th Street', '', 'Anytown', 'OH', '12345' from names where firstName='John' and lastName='Doe';

insert into addresses (nameID, addr1, addr2, city, state, postal_code)
select ID, '16 7th Avenue', 'Apt. 9', 'Big City', 'AZ', '23456' from names where firstName='Mary' and lastName='Smith';

insert into addresses (nameID, addr1, addr2, city, state, postal_code)
select ID, '5432 Rose Ct.', 'Number 3', 'Townburg', 'VT', '34567' from names where firstName='Bill' and lastName='Jones';

insert into addresses (nameID, addr1, addr2, city, state, postal_code)
select ID, '456 7th Street', '', 'Hilltop', 'FL', '98756' from names where firstName='Dave' and lastName='White';

insert into addresses (nameID, addr1, addr2, city, state, postal_code)
select ID, '98 Long Road', '', 'Noplaceville', 'AK', '74839' from names where firstName='Jane' and lastName='Tate';

I used this line, source /home/user/db.sql

and I got these errors.

ERROR 1064 (42000) at line 1 in file: '/home/user/db.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'create database contacts' at line 3
ERROR 1049 (42000) at line 5 in file: '/home/user/db.sql': Unknown database 'contacts'
ERROR 1046 (3D000) at line 7 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 14 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 25 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 28 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 31 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 34 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 37 in file: '/home/user/db.sql': No database selected
ERROR 1046 (3D000) at line 40 in file: '/home/user/db.sql': No database selected

Any ideas? Thanks.

2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by cereal
1

Hi,

in the first line (drop ...) is missing the separator (the semi-colon in this case), so all the following falls into a syntax error.

Edited by cereal

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.