patternsqlModerate
Tables not displaying after creating database by script. Do I need to insert?
Viewed 0 times
afterscripttablesinsertneedcreatingdisplayingdatabasenot
Problem
I successfully created (scripted) a database in SQL Server 2012.
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 an error:
" Msg 208, Level 16, State 1, Line 1 Invalid object name
'ContactInfo'. "
What am I doing wrong? Why aren't the database tables listed?
Here is the actual script I used:
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 an error:
" Msg 208, Level 16, State 1, Line 1 Invalid object name
'ContactInfo'. "
What am I doing wrong? Why aren't the database tables listed?
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));Solution
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
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).
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
GOCode Snippets
use [YOUR_DATABASE]
GO
select * from sys.tables
GOContext
StackExchange Database Administrators Q#140360, answer score: 11
Revisions (0)
No revisions yet.