Managing Databases and Tables
Managing Databases and Tables
master
tempdb
model
msdb
Resource
The primary data file contains database objects. It can be used for
the system tables and objects. It is the starting point of the database
and points to other files in the database. Every database has one
primary data file. It has a .mdf extension.
The transaction log file records all modifications that have occurred in
the database and the transactions that caused those modifications.
The transaction log files hold all the transaction information and can
be used to recover a database. At least one transaction log file must
exist for a database. However, there can be more than one transaction
log files. The minimum size of a transaction log file is 512KB. The size
of the transaction log file should be 25 -40 percent of the size of the
database. The log files have a .ldf extension.
Creating Databases
You can delete a database when it is no longer required. This causes all
the database files and data to be deleted. Only the users with
sysadmin role and the database owner have the permissions to delete a
database. The DROP DATABASE statement is used to delete a
database.
Managing Tables
A table is a database object used to store data. Data in a table is
organized in rows and columns. Each row in a table represents a unique
record and each column represents an attribute of the record. The
column names within a table must be unique, but the same column name
can be used in different tables within a database. As a database
developer, you need to create tables to store data. While creating
tables in a relational database, you must ensure that no one enters
invalid data in it. For this, you need to apply certain rules and
constraints on columns that specify the kind of data to be stored. In
addition, you need to specify the relationships between various tables.
If you want to store a large volume of data in a table, you can create a
partitioned table. This helps in improving query performance. In
addition to creating tables, you are responsible for managing tables.
Management of tables involves modifying tables to add columns or to
change the rules imposed on the table. It also involves deleting tables,
when they are no longer required.
Creating a Table
Creating a Table
In SQL Server, you can create a table by using the CREATE TABLE
statement. The syntax of the CREATE TABLE statement is:
LeaveReason varchar(100),
)
Example (Creating database and Tables)
BEGIN
END
GO
BEGIN
END
GO