Home > Blockchain >  SQL Error Code: 1049. Unknown database 'dbo'
SQL Error Code: 1049. Unknown database 'dbo'

Time:11-29

I am trying to create a database use mysql workbench and I keep getting this error and my code looks fine. Not sure how I can resolve this. This is the error I am getting: Error Code: 1049. Unknown database 'dbo'. I have tried so many things but only the first two lines of creating and using the database works. [screenshot attached]

enter image description here


use employeedb;

create table dbo.Department(
DeprartmentId int AUTO_INCREMENT,
DepartmentName nvarchar(500),
PRIMARY KEY(DepartmentId)
);

insert into dbo.Department(DepartmentName) values ('IT');
insert into dbo.Department(DepartmentName) values ('Support');

create table dbo.Employee(
EmployeeId int AUTO_INCREMENT,
EmployeeName nvarchar(500),
Department nvarchar(500),
DateOfJoining datetime,
PhotoFileName nvarchar(500),
PRIMARY KEY(EmployeeId)
);

insert into dbo.Employee(EmployeeName,Department,DateOfJoining,PhotoFileName) 
values                  ('John','IT','2022-11-27','anonymous.png');

select * from dbo.Employee;

CodePudding user response:

You seem to be using SQL Server syntax, which won't work on MySQL. Here is your script updated for MySQL:

USE employeedb;

CREATE TABLE Department (
    DeprartmentId int AUTO_INCREMENT,
    DepartmentName varchar(500),
    PRIMARY KEY(DepartmentId)
);

INSERT INTO Department(DepartmentName) VALUES ('IT');
INSERT INTO Department(DepartmentName) VALUES ('Support');

CREATE TABLE Employee (
    EmployeeId int AUTO_INCREMENT,
    EmployeeName varchar(500),
    Department varchar(500),
    DateOfJoining datetime,
    PhotoFileName varchar(500),
    PRIMARY KEY(EmployeeId)
);

INSERT INTO Employee (EmployeeName, Department, DateOfJoining, PhotoFileName) 
VALUES ('John', 'IT', '2022-11-27', 'anonymous.png');

SELECT * FROM Employee;

CodePudding user response:

Seems you are changing from MSSQL to MySQL, for MySQl do not need "dbo", just:

use employeedb;

create table Department( DeprartmentId int AUTO_INCREMENT, DepartmentName nvarchar(500), PRIMARY KEY(DepartmentId) ); ....

  • Related