使用 T-SQL 创建表 - 在对象资源管理器中看不到创建的表

Creating table with T-SQL - can#39;t see created tables in Object explorer(使用 T-SQL 创建表 - 在对象资源管理器中看不到创建的表)
本文介绍了使用 T-SQL 创建表 - 在对象资源管理器中看不到创建的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

使用微软 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 创建表 - 在对象资源管理器中看不到创建的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to check if VARCHAR strings are (not) hexadecimal?(如何检查 VARCHAR 字符串是否为(非)十六进制?)
Arithmetic overflow error converting IDENTITY to data type int(将 IDENTITY 转换为数据类型 int 的算术溢出错误)
Where clause if there are multiple of the same ID(如果有多个相同的 ID,Where 子句)
Azure SQL: Invalid Object Name using Powershell#39;s quot;Invoke-sqlcmdquot; on Adventureworks(Azure SQL:使用 Powershell 的“Invoke-sqlcmd的无效对象名称在 Adventureworks 上)
How to Convert Table Data into xml format using sql with multiple sub nodes(如何使用具有多个子节点的sql将表数据转换为xml格式)
T-SQL - compare strings char by char(T-SQL - 按字符比较字符串)