SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create Table in Specified Database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/09/2012 :  09:26:49  Show Profile  Reply with Quote
I am new to SQL and using SQL Server 2012 Studio.
I am also generating VBA code in EXCEL to run with SQL.

I created a new database called Test by right clicking on Databases and add new one. Similarly I created a new table. No problem all worked fine. I can see a database called Test and my new table.

If I run

CREATE TABLE OrderItems
(
  order_num  int          NOT NULL ,
  order_item int          NOT NULL ,
  prod_id    char(10)     NOT NULL ,
  quantity   int          NOT NULL ,
  item_price decimal(8,2) NOT NULL 
); 

It Executes but I can't find the Table.
I have now used the USE command to create in a specified database and that works but I still can't find the first table created. I can't find a Tables section (other than my Test database)

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1795 Posts

Posted - 06/09/2012 :  11:15:30  Show Profile  Visit jackv's Homepage  Reply with Quote
Is it possible the it was created in another database?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48026 Posts

Posted - 06/09/2012 :  11:24:11  Show Profile  Reply with Quote
quote:
Originally posted by peterhw

I am new to SQL and using SQL Server 2012 Studio.
I am also generating VBA code in EXCEL to run with SQL.

I created a new database called Test by right clicking on Databases and add new one. Similarly I created a new table. No problem all worked fine. I can see a database called Test and my new table.

If I run

CREATE TABLE OrderItems
(
  order_num  int          NOT NULL ,
  order_item int          NOT NULL ,
  prod_id    char(10)     NOT NULL ,
  quantity   int          NOT NULL ,
  item_price decimal(8,2) NOT NULL 
); 

It Executes but I can't find the Table.
I have now used the USE command to create in a specified database and that works but I still can't find the first table created. I can't find a Tables section (other than my Test database)



it may be that you've created it in master database.

try running this and see what it returns

EXEC sp_Msforeachdb 'IF EXISTS(SELECT 1 FROM ?.INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''OrderItems'') SELECT ''?'''


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/11/2012 :  05:22:06  Show Profile  Reply with Quote
The Query returns 'master'.

I assume this TABLE (and others) are in the 'master' database but I just can't locate them i.e. there is nothing called Tables under the Master database (there is a Tables entry under my Test database)
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1795 Posts

Posted - 06/11/2012 :  10:34:36  Show Profile  Visit jackv's Homepage  Reply with Quote
Try this sql code:
use master
GO
select * from sys.sysobjects where xtype = 'U'order by name

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/11/2012 :  11:52:34  Show Profile  Reply with Quote
Thanks

Yes - that appears to list them but no still idea where to find them.

It doesn't really matter but I created these very early on and i9n practice I should have created in a new database 'Order_Processing' or similar and I would like to delete the originals
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48026 Posts

Posted - 06/11/2012 :  15:12:32  Show Profile  Reply with Quote
quote:
Originally posted by peterhw

Thanks

Yes - that appears to list them but no still idea where to find them.

It doesn't really matter but I created these very early on and i9n practice I should have created in a new database 'Order_Processing' or similar and I would like to delete the originals


just expand system databases master and expand tables folder within them to find required tables

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1795 Posts

Posted - 06/12/2012 :  00:42:32  Show Profile  Visit jackv's Homepage  Reply with Quote
If you can view them via the SELECT statement - then you can issue a DROP TABLE command. Assuming you have the permissions

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/12/2012 :  02:26:40  Show Profile  Reply with Quote

quote:

just expand system databases master and expand tables folder within them to find required tables



That's what I'd expect to be able to do .... but there is no 'Tables' or 'Database Diagrams' folders listed under Master (or other system databases)
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/12/2012 :  02:36:50  Show Profile  Reply with Quote
quote:
Originally posted by jackv

If you can view them via the SELECT statement - then you can issue a DROP TABLE command. Assuming you have the permissions



Many thanks - worked no problem - the Tables were not visible in the 'Object Explorer' window under master (see last reply / post)
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/12/2012 :  02:42:55  Show Profile  Reply with Quote
Many thanks for for help
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
1795 Posts

Posted - 06/12/2012 :  11:07:50  Show Profile  Visit jackv's Homepage  Reply with Quote
Not a problem. Strange you can't expand the Object Explorer - have you thought of installing a later version of SSMS?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/12/2012 :  11:18:07  Show Profile  Reply with Quote
Thanks again.
I have only just installed the 'system' i.e. SQL Server 2012 with following components
Microsoft SQL Server Management Studio 11.0.2100.60
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 8.0.7601.17514
Microsoft .NET Framework 4.0.30319.269
Operating System 6.1.7601

Don't know what SSMS is or how to update (or if needs to do so)

Edited by - peterhw on 06/12/2012 11:19:28
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 06/12/2012 :  11:38:05  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
ssms = sql server management studio.

Sometimes when you create a new table the GUI doesn't refresh. You can right click on the db or the tables folder in the db and click on refresh.

Also you should see a toolbar on the top of SSMS by default that shows you which db you are running commands in.

Stay out of master.

=== Transact Charlie ==============================
   '''; DROP DATABASE Problems; -- '
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

peterhw
Starting Member

United Kingdom
12 Posts

Posted - 06/13/2012 :  03:43:09  Show Profile  Reply with Quote
quote:
Originally posted by Transact Charlie

ssms = sql server management studio.


No need to update / upgrade then - I assume.

quote:

Sometimes when you create a new table the GUI doesn't refresh. You can right click on the db or the tables folder in the db and click on refresh.



The original databases were loaded on my very first entry into SQL with a series of scripts to CREATE tables and POPULATE tables. I have been in/out of ssms( I remembered!) and rebooted since the original installation. I subsequently created my Test database and wanted to remove the original tables and install in Test.

quote:

Also you should see a toolbar on the top of SSMS by default that shows you which db you are running commands in.

Stay out of master.




Yes can see the Toolbar and now want to keep well away from Master !
Go to Top of Page

lisayling
Starting Member

China
5 Posts

Posted - 06/13/2012 :  05:38:45  Show Profile  Reply with Quote
en, i can accept this view, but not the fully
unspammed
lisayling
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000