SQL Server 2014 Management Studio - sql-server-2014

I get this error:
Msg 4902, Level 16, State 1, Line 62
Cannot find the object "tblDepartment" because it does not exist or you do not have permissions.
when trying to run this SQL statement:
create table tblDepartment
(
depNum char(5) not null,
depName varchar(20),
mgrSSN char(5),
mgrAssDate char(5)
)

try to use this code instead
create table dbname.schema.tblDepartment
(
depNum char(5) not null,
depName varchar(20),
mgrSSN char(5),
mgrAssDate char(5)
)
SELECT *
FROM dbname.schema.tblDepartment.
Note : Define your dbname and schema so that you can directly select your created table.

Related

SQL Error Code: 1049. Unknown database 'dbo'

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]
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;
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;
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)
);
....

Mysql Error 1064 when trying to create a table

I'm trying to create a table so that I can pass in a csv file to load it into the table but I'm getting this error and I'm not sure why. Here's what I have:
CREATE TABLE imdb(
-> rank int auto_increment PRIMARY key,
-> title varchar(255),
-> genre varchar(255),
-> director varchar(255),
-> actors varchar(255),
-> year int,
-> rating decimal(1,1),
-> votes int,
-> metascore int
-> );
Here is the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rank int
auto_increment PRIMARY key,
title varchar(255),
genre varchar(255),
dir' at line 2
Those arrows shouldn't be there (maybe something that got added when copy/pasting?). Also, rank and year are reserved words (thanks #
Aloiso Gomes) so you have to add backticks to allow the name anytime you reference it (stored procs, selects, inserts, etc.)
This works:
CREATE TABLE imdb(
`rank` int auto_increment PRIMARY key,
`title` varchar(255),
`genre` varchar(255),
`director` varchar(255),
`actors` varchar(255),
`year` int,
`rating` decimal(1,1),
`votes` int,
`metascore` int
);
INSERT INTO imdb (title,genre) VALUES
('Fast Furious 1', 'racing'),
('Fast Furious 2', 'racing'),
('Fast Furious 3', 'racing?'),
('Fast Furious 4', '"racing"');
SELECT `rank`, title, genre FROM imdb;

how can I create second table in mysql? 1050 error

i'm creating second table in HEIDI SQL, but it doesn't work.
it shows 1050 error: user1 aleady exists.
I aleady created user1 table and I try to create user2 table. However it doesn't
#2. TABLE
CREATE TABLE user1(
user_id INT,
name VARCHAR(20),
email VARCHAR(30),
age INT(3),
rdata DATE
);
# TABLE 2
CREATE TABLE user2(
user_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
email VARCHAR(30) UNIQUE NOT NULL,
age INT(3) DEFAULT 30,
rdate TIMESTAMP
);
You can run this script, which will avoid this error "1050 error: user1 aleady exists.":
CREATE TABLE IF NOT EXISTS `user1 ` (
user_id INT,
name VARCHAR(20),
email VARCHAR(30),
age INT(3),
rdata DATE
);
NB: your user1 table doesn't have a primary key and for the age column, it's advisable to store the date of birth because the age can be calculated.
I would advise you to write the script using drop table if exists:
DROP TABLE IF EXISTS user1;
CREATE TABLE user1 (
user_id INT,
name VARCHAR(20),
email VARCHAR(30),
age INT(3),
rdata DATE
);
# TABLE 2
DROP TABLE IF EXISTS;
CREATE TABLE user2(
user_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
email VARCHAR(30) UNIQUE NOT NULL,
age INT(3) DEFAULT 30,
rdate TIMESTAMP
);
CREATE TABLE IF NOT EXISTS will leave the previous version of the table -- which is troublesome if you make changes to the definitions. Using such constructs, I have spent a fair amount of time debugging code when the structure of a table didn't change.

If anyone can help me because im stuck in count query in jsp (im new in databases )

I cant run this query i dont know why i thought it was correct but the select in jsp is returning nothin (also sorry for my bad english) im a student in highschool and not its not fo a project but fo educational purpose only.
Thank you for understanding.
String query = "select s_int,count(bio) from users,scientific_interests"
" where scientific_interests.Record_number = users.Record_number"
"and s_int = '"+SCIENTIFIC_INTRESTS+"' ";
MYSQL DB TABLES
CREATE TABLE IF NOT EXISTS scientific_interests (
intId INT(100) AUTO_INCREMENT,
Record_number VARCHAR(100) NOT NULL,
s_int varchar(100) not null,
PRIMARY KEY (intId),
FOREIGN KEY(Record_number) references users(Record_number)
);
CREATE TABLE IF NOT EXISTS users (
Record_number VARCHAR(100) NOT NULL,
name CHAR(50),
surname CHAR(50),
institute VARCHAR(50),
department VARCHAR(50),
bio VARCHAR(500),
b_day INT(10),
b_month INT(10),
b_year INT(10),
PRIMARY KEY (Record_number)
);
Try using a join:
String query = "select s_int,count(bio) from scientific_interests JOIN users ON scientific_interests.Record_number = users.Record_number WHERE s_int = '"+SCIENTIFIC_INTRESTS+"' ";

SQL oracle Developer error

CREATE TABLE person_details
( id NOT NULL AUTO_INCREMENT,
name varchar(100),
age int,
gender varchar(8),
adult varchar(10),
contact_no int,
address varchar(255),
pnr_number int
)
Error at Command Line:2 Column:15
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
You forgot to define the type of id field here:
( id NOT NULL AUTO_INCREMENT,
Should be something like:
( id INT NOT NULL AUTO_INCREMENT,
^^^^
And make it as a primary key like
pnr_number int,
PRIMARY KEY (id)