Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how is meaning of this code?

Author  Topic 

beliveinmyshelf
Starting Member

15 Posts

Posted - 2007-05-28 : 00:33:08
i'm learning SQL server in APTECH. it's difficult. i use "book online" to look up the syntax, code example.....
and i have a code as follow :

use master
go
create database ex1
on
(
name=ex1_file,
filename='C:\ex1_file.mdf',
size=10,maxsize=10,filegrowth=10
)
log on
(
name=ex1_log
filename='C:\ex1_log.ldf',
size=5,maxsize=5,filegrowth=10
)
go

but i don't know this section in above code :

USE MASTE
GO

please explain for me
thank very much

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-28 : 00:34:34
It means make Master database as my current database, henceforth.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-28 : 02:26:56
in other words, it means the CREATE DATABASE statement is executed in the context of the master database.


www.elsasoft.org
Go to Top of Page

beliveinmyshelf
Starting Member

15 Posts

Posted - 2007-05-28 : 02:43:11
but ex1 database is equivalent with master database because they are database together.why use its in above code :

USE MASTER
GO
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-28 : 02:54:07
quote:
but ex1 database is equivalent with master database because they are database together

What do you mean by this ?
The script you posted basically is for creating a new database named ex1. Before creating the new database ex1, it set the current database context to master.


KH

Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-28 : 02:55:56
maybe this example will help. this creates a new database called foo, switches to the context of foo, then creates a table called bar. bar is created in foo because it's executed in the context of foo.


use master
go
create database foo
go
use foo
go
create table bar(id int)
go


here's a similar one, but bar is created in the master database (oops!) because the "use foo" statement is missing:


use master
go
create database foo
go
create table bar(id int)
go



www.elsasoft.org
Go to Top of Page

beliveinmyshelf
Starting Member

15 Posts

Posted - 2007-05-28 : 03:24:31
thank very much.it's meaning
my database (ex1) isn't relate with master database.
formerly, i thought they have a relation. it's crazy.thank very much
Go to Top of Page
   

- Advertisement -