0

I tried searching for this exact scenario, but had no luck.

I want to add a row to a table in Microsoft SQL via Microsoft SQL Server Management Studio.

The table name is dbo.BlockedEmails and the column within it that I want to add the row to is Email.

There are other columns in the table such as Timestamp and Source, but I am hoping that those columns are filled automatically or are unnecessary.

Would the correct syntax be:

INSERT [INTO] dbo.BlockedEmails [(Email)] [email protected]
2
  • 1
    Google has millions of answer for your question. Commented Jul 27, 2016 at 12:25
  • 1
    Why don't you just consult the official MSDN documentation on SQL Server which has all the answers for you! Just go look for yourself - full syntax spec, lots of samples ..... Commented Jul 27, 2016 at 12:43

3 Answers 3

2

The correct syntax is:

INSERT INTO dbo.BlockedEmails(Email)
    VALUES ('[email protected]');

You can also use INSERT . . . SELECT:

INSERT INTO dbo.BlockedEmails(Email)
    SELECT '[email protected]';

Note: This will only work if all other columns are either NULL-able or have default values.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you both, unfortunately when I enter it I get the error message: Msg 208, Level 16, State 1, Line 2 Invalid object name 'dbo.BlockedEmails'
@brando Probably you're runnig your query while your current database in Management Studio is different from those holding this table. Either use fully qualified table name, including DB name (i.e. MyDB.dbo.BlockedEmails) or switch current DB by command use MyDB where MyDB is name of databesу holding BlockedEmails table.
1

Correct syntax will be

INSERT INTO dbo.BlockedEmails (Email) values (`[email protected]`)

or

INSERT INTO dbo.BlockedEmails (Email) select `[email protected]`

String values should be enclosed in single quotes ' and also square brackets are redundant in this case.

Comments

0

If you want to insert multiple rows use comma separated

INSERT INTO dbo.BlockedEmails (Email) values
('[email protected]'),
('[email protected]'),
('[email protected]')

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.