hbk
hbk

Reputation: 11184

Creating table with T-SQL - can't see created tables in Object explorer

use Microsoft SQL

Try to create table using T-SQL language. Code is very simple, executed succesfull, but i don't see created table in Object Explorer. Try restart/reconnect/refresh/reexecuting - result the same - cant see this table. Also try to do it manually (by right click mouse in tree in the Object explorer - all ok - can see just created table).

Code:

USE tempdb 
    IF OBJECT_ID('dbo.Employees','U') IS NOT NULL
DROP TABLE dbo.Employees;
CREATE TABLE dbo.Employees
(
    empid INT NOT NULL,
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    hiredate DATE NOT NULL,
    mgrid INT NULL,
    ssn VARCHAR(20) NOT NULL,
    salary MONEY NOT NULL
);

Screen shot

enter image description here

Think that the problem is very simple, but try to find answer and stack a little bit. Why i don't see just created table? Is this code is correct for creating table?

Upvotes: 3

Views: 8141

Answers (1)

M.Ali
M.Ali

Reputation: 69504

It is because you are creating that table in TempDB.

enter image description here

From this drop down select the right DataBase.

OR

execute the following statement before you execute the Create Table Statement. Something like

USE TestDB
GO

Create Table ....

Upvotes: 6

Related Questions