問題描述
使用微軟 SQL
嘗試使用 T-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).
代碼:
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
);
屏幕截圖
覺得這個問題很簡單,但是試著找答案,稍微堆疊一下.為什么我沒有看到剛剛創建的表?此代碼是否適用于創建表?
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?
推薦答案
這是因為您正在 TempDB 中創建該表.
It is because you are creating that table in TempDB.
從此下拉列表中選擇正確的數據庫.
From this drop down select the right DataBase.
或
在執行創建表語句之前執行以下語句.類似的東西
execute the following statement before you execute the Create Table Statement. Something like
USE TestDB
GO
Create Table ....
這篇關于使用 T-SQL 創建表 - 在對象資源管理器中看不到創建的表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!