The data of a database is stored in files (of a file system). These files can be grouped into so called file groups.
Schemas
A database has one or more
schemas. A schema is a group of objects (such as tables, views, stored procedures etc.) with a specific
ownership.
Some special objects such as certificates and
asymmetric keys are not found in a schema but in the database itself.
select * from DB.SCH.OBJ;
select * from SRV.DB.SCH.OBJ;
Database owner
A database has an owner:
select
suser_sname(owner_sid) database_owner,
name database_name,
state_desc , -- Online?
owner_sid
from
sys.databases
Within a database, its owner is known as the dbo of the database.
Attached and detached database
In order to use the data that is stored in a
database data file, the data file (that is: the database) must be attached to an
instance.
A database file can be attached to an instance with a variation of the create database statement
:
create database tq84_db_copy on (filename = 'd:\ata\base\file.mdf') for attach;
go
An attached database can be detached with
sp_detach_db tq84_db_copy;
See also
sp_helpdb
shows some rudimentary information about databases.
dbcc clonedatabase(…)
creates a new database and then clones the
structure of an existing database into the new one.
The MS-Access command
doCmd.copyDatabaseFile
copies an Access database to an SQL server database (a database file with the extension
.mdf
).
Then, there is also doCmd.transferSQLDatabase