SQL Server Creating a table in SQL but doesn't show up in 'tables' folder

mepcadol  于 2023-02-28  发布在  其他
关注(0)|答案(3)|浏览(158)

I am currently trying to create a table in SQL. When I run the query I get the text, "Command(s) completed successfully."

However, this does not add the table to table folder on the left hand side. As far as I can tell, despite the fact that Visual Studio is telling me it was created, it hasn't been created.

I have refreshed the folder and the whole server multiple times.

CREATE TABLE [dbo].MembersTable
(
MemberID INT NOT NULL,
FirstName VARCHAR(100),
LastName VARCHAR(100),
MemberAddress VARCHAR(200),
TypeOfMembershipID VARCHAR(20),
PhoneNumber CHAR(11),
MembershipStart DATE,
MembershipEnd DATE,   
Notice BIT,
TypeOfPaymentID VARCHAR(20),
PRIMARY KEY (MemberID),
FOREIGN KEY (TypeOfMembershipID) REFERENCES   [dbo].MemberTypeTable(TypeOfMembershipID)
)
7hiiyaii

7hiiyaii1#

you have to refresh the list, by right clicking on the Tables node in the left menu.

Also, check that you are not creating the Table in the Master database

wydwbb8l

wydwbb8l2#

Check these two items:

1.Check your active database. You can set active database by using the :

USE YOUR_DN_NAME
GO

and after that write your CREATE TABLE code.

  1. If the active database is set correctly but you still can not see the table, you need to right click on the Table node, in object explorer and select REFRESH to see the table. You can also write a simple SELECT query to see whether the table exists or not. If table does not exists SQL SERVER will raise an error indicating that 'Invalid Object name xxxx'
yh2wf1be

yh2wf1be3#

Make sure you have selected the DB where in you want to create the table. I selected the folder Tables > new query instead of Database > new query.

相关问题