0

I am trying to create a row security level over my table for the user department

CREATE TABLE Student_Table 
(
    Title varchar(10) NULL,
    DateofBirth DATE NULL,
    BF1 varchar(10) NULL,
    Language varchar(20) NULL,
    Qualification varchar(20) NULL,
    Programme varchar(20) NULL,
    Curriculum varchar(20) NULL,
    Level int NULL,
    Department varchar(max) NULL
)

Department column contains

Level 1: General Staff
Level 2: IT Management
Level 3: Senior Managers

When I try create users

CREATE USER Manager WITHOUT LOGIN;
CREATE USER Level 1: General staff WITHOUT LOGIN;
CREATE USER Level 2:IT Management WITHOUT LOGIN;
CREATE USER Level 3: Senior Managers WITHOUT LOGIN;
GO

I get the following errors:

Msg 102, Level 15, State 1, Line 35
Incorrect syntax near '1'

Msg 102, Level 15, State 1, Line 36
Incorrect syntax near '2'

Msg 102, Level 15, State 1, Line 37
Incorrect syntax near '3'

Can someone please assist me.

0

2 Answers 2

0

The error is simple. When name of an object should have space then whole name must be within [].

CREATE USER Manager WITHOUT LOGIN;
CREATE USER [Level 1: General staff] WITHOUT LOGIN;
CREATE USER [Level 2:IT Management] WITHOUT LOGIN;
CREATE USER [Level 3: Senior Managers] WITHOUT LOGIN;
Sign up to request clarification or add additional context in comments.

Comments

0

The first part of troubleshooting is break your code into pieces and work out which line failed first..

It was

CREATE USER Level 1: General staff WITHOUT LOGIN; right?

All the prior stuff is irrelevant.

This is the correct syntax:

CREATE USER [Level 1: General staff] WITHOUT LOGIN;

This needs to be repeated for your other user creation.

But you should really avoid identifiers with spaces or special characters altogether

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.