I couldn't able to create a table in SQL. This is my code. And it told me that it had been a mistake:
permission denied for schema public LINE 1: ...a8da3e90-dbed-11ec-b5aa-513dc633b9bb*/ CREATE TABLE student ^
CREATE TABLE student
(
student_id INT PRIMARY KEY,
nama VARCHAR(20),
major VARCHAR(20)
);
CodePudding user response:
When you're creating tables you're doing with a certain user (the one you've connected to the database). That user has permissions on what it can do in the Database/Schema.
So you can either create your own schema and create your table there or add permissions/roles to your user so that you can create the table in the public schema. But probably safest to do it like this:
CREATE DATABASE IF NOT EXISTS new_database1;
CREATE TABLE new_database1.student
(
student_id INT PRIMARY KEY,
nama VARCHAR(20),
major VARCHAR(20)
);
CodePudding user response:
If you don't specify it, it will create it in the public schema and you don't have permissions.
Create table schema.tableName
In your case change another schema
CREATE TABLE dbo.student ( student_id INT PRIMARY KEY, nama VARCHAR(20), major VARCHAR(20) );