Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Thursday, March 22, 2012

A very beginer question: error in creating table

I am new in T-SQL. I have just create a empty database and would like to create some table in it. So I type the following in SQL Query Analyzer:

CREATE TABLE mydatabasename.mytablename (

some code here
)
But when execute, it give me an error from the first line "Specified owner name 'mydatabasename' either does not exist or you do not have permission to use it."

when I remove mydatabasename it inserts the table in to the master database, not in my database.

How can I insert the table into my database? Should I use SQL Query Analyzer or use others program? I 've tried to use the command "create table" in enterprise manager but it immediately give another error, some what like "could not use empty column name ... "
Seem to be too simple question, but I am really appreciate your helpWhen you use the SQL Query Analyzer do you choose from the dropdown your newly created Database?|||CREATE TABLE mydatabasename.mytablename

should be

CREATE TABLE mydatabasename.dbo.mytablename

A fully qualified name is
servername.databasename.owner.object

You can't skip one like you're doing. You can omit them from left to right, but can't skip a part.|||Thanks all. I will try both, select the newly database and use databasename.dbo.tablename.

Infact, I use to think about using "databasename.dbo.tablename" but then think it 's ridiculous for a try. What a mistake. It's my because my poor English make me sometime not understand the full syntax.

Thank you.

Sunday, March 11, 2012

A SQL / STored procedure question.

I have following two tables.

Table1 (Columns: ID, SessionID, URL) Note: URL Column currently is empty. Table1 has one record per SessionID.

Table2 (Columns: ID, SessionID, fromURL) Note: Table 2 has multiple records per Session ID.

So in essence, for one SessionID in Table1 there are multiple records in Table2.

Also the value in fromURL column in Table2 is unique for a SessionID.

What I want to do:

1). Select Table2.fromURL where Table1.SessionID = Table2.SessionID with DISTINCT Table2.fromURL.(I will get lot of records from the above statement)

2). For each record in step 1,Insert value from Table2.fromURL into Table1.URL where Table2.SessionID = Table1.SessionID

Phew.. difficult to explain.. i am sure.. easy to implement.Any help would be appreciated. Regards.

UPDATE Table1 SET URL = fromURL FROM Table2 WHERE Table2.SessionID = Table1.SessionID