Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4110606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:57:22+00:00 2026-05-20T21:57:22+00:00

This is probably stupid simple, but for some reason I’m having trouble getting it

  • 0

This is probably stupid simple, but for some reason I’m having trouble getting it to work. I have a typical import script I’m trying to run on a MS SQL server with one master user (as opposed to a single user with only access to one database).

When I run the .SQL script, it creates the database and then starts to create tables. Here’s where it gets interesting. It’s not creating the databases under the DB I just made. It’s throwing the tables under the “System Databases” view and not restricting the table creation to the DB that was just created.

I have tried:

CREATE TABLE table_name
CREATE TABLE database_name.table_name

Maybe I’m overlooking something really easy. I don’t usually run into this with MySQL with a single user mapped to one database, I think since the user can only see that one database, so MySQL assumes it must be the one to work with.

The difference now is that I’m using MSSQL 2008 and maybe it works a little differently and I’m overlooking something. Thanks for your help!


Tried this too. No luck. Says database doesn’t exist when it tries to create the table. I would think being a top/down read of the query script it would first create the database, then try to create the table afterwards.

CREATE DATABASE DATABASENAME;
CREATE TABLE DATABASENAME.dbo.TABLENAME
  (
     field_one   VARCHAR(100) NOT NULL,
     field_two INT NOT NULL,
     PRIMARY KEY(field_one)
  )

This is a working example after getting it all figured out. This syntax works well and I don’t need to specify the DBO pathing stuff before table names this way. Cleaner and got me the results I was looking for. Thanks everyone.

IF Db_id('DBNAME') IS NULL
  CREATE DATABASE DBNAME;

GO

USE [DBNAME];

GO

CREATE TABLE TABLENAME
  (
     COL1   VARCHAR(100) NOT NULL,
     COL2 INT NOT NULL,
     PRIMARY KEY(COL2)
  )

INSERT INTO TABLENAME
            (COL1,
             COL2)
     VALUES('1234',1001),
            ('1234',1002),
            ('1234',1003),
            ('1234',1004)

It basically just does a check to make sure database is created before doing anything else, then sets the USE database to the one I’m working with. Everything else is just normal SQL, so have fun. Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:57:23+00:00Added an answer on May 20, 2026 at 9:57 pm

    Probably you need to include the USE sentence at the begining of your script in order to indicate the database as follows:

    USE [database_name]
    GO
    

    By default SQL-SERVER use the master DB that´s listed under system databases.

    Other way is to use the database prefix, but including the owner:

    INSERT INTO database_name.dbo.table_name
    INSERT INTO database_name..table_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very simple and stupid question to ask, but I have
Well this is probably a stupid question with a simple answer but when using
This is probably a really stupid MSBuild question but if I have <ItemGroup> <Dll
this is probably something stupid, but i can't figure it out. I'm getting a
This probably sounds really stupid but I have noo idea how to implement jquery's
This is probably something simple but it's driving me nuts. I'm making some pagination
This is probably something very simple but I'm not getting the results I'm expecting.
this is probably a stupid question but I can't seem to find the answer.
This is probably a stupid question, but how much of a security risk is
This is probably a stupid question, but what exactly is a non-blocking web server?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.