Alex
Alex

Reputation: 37

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

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

Upvotes: 0

Views: 9193

Answers (3)

YouT
YouT

Reputation: 1

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.

Upvotes: 0

Kobi
Kobi

Reputation: 2524

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

enter image description here enter image description here

Upvotes: 3

Vahid Farahmandian
Vahid Farahmandian

Reputation: 6568

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'

Upvotes: 0

Related Questions