I'm trying to create a table (based off of a .csv file I've been working with) within SQL, but I'm getting the following message:
SQL Error: ORA-01031: insufficient privileges
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without the necessary privileges.
What do I need to change to create the table?
Here is the my code to create the table--then I have a bunch of INSERT INTO lines.
CREATE TABLE Water_Birth_Consent
(
NAME VARCHAR(24) NOT NULL
,MRN INTEGER NOT NULL
,DATE_SIGNED VARCHAR(10) NOT NULL
,EDD VARCHAR(10) NOT NULL
,DEL DATE
,WB VARCHAR(5)
,study_id VARCHAR(17)
,comments VARCHAR(42)
,EMPI INTEGER
);
Another user with sufficient privileges (DBA) needs to grant your user the create table privilege. This is the command they would run:
grant create table to <your-user>;
Once you are able to create the table, you won't need any additional special permissions to insert data into the table.
Related
I'm new to the MS SQL server. Our client has given us a SQL server DB and for this DB they have configured the Service Principal Authentication. So I logged into the DB using my client company account and then I tried to create a table without giving any schema name. for example
CREATE TABLE visits (
visit_id INT PRIMARY KEY IDENTITY (1, 1),
first_name VARCHAR (50) NOT NULL,
last_name VARCHAR (50) NOT NULL,
visited_at DATETIME,
phone VARCHAR(20),
store_id INT NOT NULL,
);
so when I ran this query it gave me the below error
Msg 2760, Level 16, State 1, Line 1
The specified schema name "aashay.amballi#<company>.com" either does not exist or you do not have permission to use it.
so now when I created the table with DBO schema it created the table.
CREATE TABLE dbo.visits (
visit_id INT PRIMARY KEY IDENTITY (1, 1),
first_name VARCHAR (50) NOT NULL,
last_name VARCHAR (50) NOT NULL,
visited_at DATETIME,
phone VARCHAR(20),
store_id INT NOT NULL,
);
So now when I tried to query this visits table without any schema (i.e. DBO) select * from visits it actually gave me the result.
Also when I ran the select SCHEMA_NAME() to check what is the default schema, it returned null. So is there a possibility that when there is no default schema that is set for a user and while creating a table without a schema name it will give that error? if that is the case then while querying without any schema how it's picking the dbo schema by default?
So I'm a bit confused about how this is working. Can anyone please explain this?
This question is regarding the question that I asked a couple of days back when I'm trying to integrate MSSQL with service principal authentication with the Django Framework - Django MigrationSchemaMissing exception on Azure SQL using service principal auth
From the CREATE TABLE description:
If type_schema_name isn't specified, the SQL Server Database Engine
references type_name in the following order:
The SQL Server system data type.
The default schema of the current user in the current database.
The dbo schema in the current database.
And what is your default schema? It depends on options of CREATE USER statement used when creating your user's account:
WITH DEFAULT_SCHEMA = schema_name Specifies the first schema that will
be searched by the server when it resolves the names of objects for
this database user.
You can skip the schema in queries, but it is a best practise to always use schemas.
CREATE TABLE production.product_colors (
color_id INT PRIMARY KEY IDENTITY,
color_name VARCHAR (50) NOT NULL,
created_at DATETIME2
);
I created table production,product_colors and column name created_at datetime2 data type and now I want change data type but I cannot. Not only one table, I cannot alter any table in the database.
ALTER TABLE production.product_colors
ADD CONSTRAINT df_current_time
DEFAULT CURRENT_TIMESTAMP FOR created_at;
When I am running above query I get this error:
Msg 208, Level 16, State 1, Procedure TR_ALTERTABLE, Line 6 [Batch Start Line 86]
Invalid object name 'TableSchemaChanges'.
I cannot understand why this error occurring. I searched google and nothing helps me.
I think the issue caused by schema. Please double-check it.
Here is a correct sample using 'dbo' schema.
Demo
Please refer to the documentation
The following example creates a DDL trigger safety with database scope, and then disables and enables it.
CREATE TRIGGER safety
ON DATABASE
FOR DROP_TABLE, ALTER_TABLE
AS
PRINT 'You must disable Trigger "safety" to drop or alter tables!'
ROLLBACK;
GO
DISABLE TRIGGER safety ON DATABASE;
GO
ENABLE TRIGGER safety ON DATABASE;
GO
I'm learning DDL to create and define an SQL database with Postgresql 10.
I have the something like the following SQL code in an .sql file, and I want to input it in psql or PgAdmin 4, just to test the syntax and see the database structure:
CREATE DATABASE database;
CREATE TYPE t_name AS
( first VARCHAR(30),
last VARCHAR(60)
);
CREATE TABLE telephone_m
( tnumber VARCHAR(15) NOT NULL UNIQUE
);
CREATE TABLE people
( curp CHAR(18) NOT NULL PRIMARY KEY,
pname t_name NOT NULL,
birth_date DATE NOT NULL,
telephone_m VARCHAR(15) REFERENCES telephone_m
);
CREATE TABLE clients
( curp CHAR(18) NOT NULL PRIMARY KEY,
cid SERIAL NOT NULL REFERENCES cards,
clocation VARCHAR(29)
) INHERITS (people);
CREATE TABLE cards
( cid BIGSERIAL NOT NULL PRIMARY KEY,
curp CHAR(18) NOT NULL REFERENCES clients,
trips SMALLINT,
distance NUMERIC,
points NUMERIC
);
CREATE TABLE drivers
( curp CHAR(18) NOT NULL PRIMARY KEY,
rfc CHAR(22) NOT NULL UNIQUE,
adress t_adress NOT NULL
) INHERITS (people);
I've tried in PgAdmin 4 making right-click on a new database -> CREATE Script, it opens Query Editor, I copy paste my code and execute it, but it returns:
ERROR: CREATE DATABASE cannot be executed from a function or multi-command string
SQL state: 25001
I've also tried using Query Tool directly from the PgAdmin tools menu with the same results.
The database is created just fine. But if you want to create object in the new DB, you have to connect to it. In any client, including pgAdmin4.
And you cannot run CREATE DATABASE inside of a transaction. Must be committed on it's own. Executing multiple commands at once is automatically wrapped into a single transaction in pgAdmin.
You have to execute CREATE DATABASE mydb; on its own (for instance by selecting only that line and pressing F5 while being connected to any DB, even the maintenance db "postgres". Then click on "Databases" in the object browser in the pgadmin4 main window / tab, hit F5 to refresh the view, click on the new DB, open up a new query tool with the flash icon (in a new window / tab) and execute the rest of your script there.
psql scripts manage by using the meta-command \c to connect to the new db after creating it, within the same session.
Asides:
"database" is no good name for a database.
CREATE TYPE AS (...), but just CREATE TABLE (...). No AS.
And you typically don't want to use the data type CHAR(18). See:
Any downsides of using data type "text" for storing strings?
Get sum of integers for UNIQUE ids
What is the overhead for varchar(n)?
Should I add an arbitrary length limit to VARCHAR columns?
There is the ; missing after the CREATE DATABASE database (and perhaps give the db a better name).
Is it possible to add a column with alter table if the column that i'm adding has a type created by me?
This is the code :
CREATE OR REPLACE TYPE istoric IS table OF number(6,2);
ALTER TABLE studenti ADD (history istoric) NESTED TABLE history STORE AS lista_tab;
I get the error :
ORA-01031: insufficient privileges.
I already tried to grant priviliges, but it doesn't change anything.
Your userid does not have the permission to alter the table. The DBA should GRANT your userid with the required rights via:
grant alter on tablename to youruserid;
Reference: Oracle alter table insufficient privileges
To learn more about the privileges in Oracle: https://docs.oracle.com/database/121/DBSEG/authorization.htm#DBSEG99869
There's nothing special you should do; I tested it on my Oracle 11g XE database. Apparently, all you need are CREATE TABLE and CREATE TYPE privileges. Have a look at this demonstration: first, as a privileged user, I'm creating a brand new user, grant privileges to it, and then do what you're doing in your question. Works just fine.
SQL> create user vlad identified by sima
2 default tablespace users
3 quota unlimited on users;
User created.
SQL> grant create session, create table, create type to vlad;
Grant succeeded.
SQL> connect vlad/sima#xe
Connected.
Session altered.
SQL> create table studenti (id number);
Table created.
SQL> create type istoric is table of number(6, 2);
2 /
Type created.
SQL> alter table studenti add (history istoric) nested table history store as lista_tab;
Table altered.
SQL>
So, who does table STUDENTI belong to? You, or someone else? If the latter, then yes - you might be lacking certain privileges.
I am trying to create a temporal table in my SQL Server database. Is anyone familiar with this error in SQL Server:
Msg 2760, Level 16, State 1, Line 5
The specified schema name "items" either does not exist or you do not have permission to use it.
I think there may be something wrong with my user privileges. Any help would be great.
Here's the code:
CREATE TABLE [items].[items_Temporal](
[itemsID] [int] NOT NULL,
[item_Name] [varchar](50) NOT NULL,
[item_Number] [int] NOT NULL,
[item_Price] [float] NOT NULL,
ValidFrom datetime2(7) GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,
ValidTo datetime2(7) GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
CONSTRAINT [PK_items_Temporal_items1ID] PRIMARY KEY CLUSTERED
(
[itemsID] ASC
),
PERIOD FOR SYSTEM_TIME(ValidFrom, ValidTo)
)
WITH(SYSTEM_VERSIONING = ON (HISTORY_TABLE = [items].[items_Temporal_History]));
From the answer of Yogesh, you can find whether the schema exists or not.
If the schema items not exist, try running
CREATE SCHEMA items
If you don't have permission to create Schema,
USE <database_name>;
GRANT CREATE SCHEMA TO <user_name>;
GO
Then create schema and run the code for creating the table.
In the case you have the schema and you are not having the permission to use it,
USE <database_name>;
GRANT CREATE TABLE TO <user_name>;
GO
Then run the code to create table.
Read Docs here
Run below query to check actually your are trying to run query in database has item schema in it or not
SELECT * FROM sys.schemas WHERE name = 'item'
If you have rows in above query then check login user from which you are trying to run this query. Also check does this user has rights to create table by this way you will have idea why this error is coming