Create table with T-SQL - unable to see created tables in Object explorer

use Microsoft SQL

Try to create a table using T-SQL language. The code is very simple, executed successfully, but I cannot see the created table in the Object Browser. Try to restart / reconnect / update / retrain - same result - cant see this table. Also try doing it manually (right clicking on the tree in the object explorer is ok - you can see the table you just created).

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
);

      

Screenshot

enter image description here

Think the problem is very simple, but try to find the answer and connect a little. Why can't I see just the created table? Is this code correct for creating the table?

+2


source to share


1 answer


This is because you are creating this table in TempDB.

enter image description here

Select the required database from the drop-down list.



OR

run the following statement before running the Create Table statement. Something like

USE TestDB
GO

Create Table ....

      

+4


source







All Articles