Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I successfully created (scripted) a database in SQL Server . My problem is that while the database itself is listed in the object explorer , the tables from the database are not. The database I scripted did not contain actual data, i.e., there were no 'Insert' statements. Is this last the reason why the tables are not listed? I tried to see if the tables were stored somehow without appearing by running an insert into statement for one of the tables in the script statement , but I get the error statement :

" Msg 208, Level 16, State 1, Line 1 Invalid object name 'ContactInfo'. "

What am I doing wrong? Why aren't the database tables listed? Thanks.

EDIT: Here is the actual script I used:

CREATE DATABASE [Name]; 
GO

CREATE TABLE Company  (CompName Varchar(10) PRIMARY KEY , CompCity VarChar(20), CompState CHAR(2), CompAddress Varchar(50), CompZip SMALLINT  );

CREATE TABLE NamePhone (CompName VarChar(10) NOT NULL PRIMARY KEY REFERENCES Company(CompName) , CompPhone   Varchar (12) NOT NULL );


CREATE TABLE ContactInfo (ContactFName NVarChar(20) PRIMARY KEY , ContactLName NVarchar(20), ContTitle Varchar(10), ContactDirPhone Char(10), ContEmail Varchar(320)
, ContCompany Varchar(10) REFERENCES Company(CompName) );

CREATE TABLE ContactReportsTo (ReportstoFName NVarChar(20) , ReportstoLName NVarchar(30), ReportstoPhone Varchar(50), ReportstoCompany Varchar(10) REFERENCES
Company(CompName),  ContactFName NVarchar(20)  REFERENCES ContactInfo(ContactFName));
share|improve this question
    
Does your script actually contain CREATE TABLE Statements, and if so did they execute? Isolate the CREATE TABLE statements and run separately to see if they successfully create your objects. – Molenpad Jun 3 at 20:04
2  
Check the default database for your login (likely master) – Martin Smith Jun 3 at 22:50
    
@Molenpad, Martin: please see the edit, I posted the actual database script. – user89723 6 hours ago
    
I noticed from your script that you have CREATE DATABASE [name]; GO and then you have your create table segment but I don't see any USE [name]; GO anywhere. Are you sure that you haven't created your tables in the database you ran the script in? Master for example? – Shaneis 6 hours ago
1  
@user89723 WebPK's answer does mention the possibility of them ending up in another database. – Martin Smith 6 hours ago
up vote 6 down vote accepted

In Object Explorer, drill down to your database, and then to Tables.

Right-click Tables and click Refresh.

If your newly created tables do not show up, perhaps you created the tables under a different database by mistake. This might happen if you were missing a USE YourDatabase in which case they would likely end up in the default database for your login (often master)

Also, the following will show all of the tables in a database. Run it for your database. If they do not show up, SQL Server did not create the tables (at all/in the desired location).

use [YOUR_DATABASE] 
GO 
select * from sys.tables 
GO
share|improve this answer
    
Thanks, I still cannot find them. I kept a copy of the script and I did save the tables under that database. – user89723 Jun 3 at 19:46
    
The following will show all of the tables in a database. Run it for yours. If they do not show up, SQL Server did not create the tables. 'use [YOUR_DATABASE] GO select * from sys.tables GO' – WebKP Jun 3 at 19:50
    
Thanks, I need to head out now, will followup Mon morning. – user89723 Jun 3 at 20:10
    
I was logging in with the Master database. If you can put that in explicitly I will give you the solution. – user89723 6 hours ago
1  
@MartinSmith: Black bear just left the cave, a.k.a, Ditto ;) – user89723 5 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.