The syntax for creating a database is as follows:
Two files whose extensions are .mdf and .ldf are responsible for creating a database. The .mdf file is a data file, whereas .ldf is log file.
- Table
- View
- Index
- Constraint
The syntax for creating a table is as follows:
(
column1 datatype NULL | NOT NULL
column2 datatype NULL | NOT NULL
column3 datatype NULL | NOT NULL
column4 datatype NULL | NOT NULL
column5 datatype NULL | NOT NULL
)
Modifications can be made to an existing table by using the ALTER TABLE statement. In order to alter the column settings of a table, the following syntax is used:
{
ALTER COLUMN column_name
{
datatype
CONSTRAINT constraint_name
}
}
In order to modify collation settings, the following syntax is used:
{
COLLATE collation_name
}
The DELETE statement is used to delete records from a table or a view. The syntax for using the DELETE statement is as follows:
The above syntax will delete all the records from a table.
The above syntax will delete records based on the search criteria.
In order to delete a table, the DROP TABLE statement is used. The syntax for deleting a table is as follows:
The syntax for creating a view is as follows:
SELECT columns
FROM table_name
[WITH CHECK OPTION
ENCRYPTION
SCHEMABINDING
VIEW_METADATA]
The WITH CHECK OPTION statement is used to force all data modifications to follow the criteria set within a SELECT statement given in the CREATE VIEW statement.
The WITH ENCRYPTION clause is used with a view or stored procedure definition. Using the WITH ENCRYPTION clause changes the view or stored procedure definition to an encrypted form. This prevents anyone from viewing the statement used to create the view or stored procedure.
The WITH SCHEMABINDING clause safeguards a view definition against any structural modification of the underlying table. If a view is created with the WITH SCHEMABINDING clause, the underlying tables cannot be deleted or altered in a way that affects the view definition.
The view specified with VIEW_METADATA can return the DBLIB, ODBC, and the OLEDB APIs. When the metadata information about a view is to be viewed, it is created with the VIEW_METADATA option.
Modifications can be made in an existing view by using the ALTER VIEW statement.
SELECT columns
FROM table_name
[WITH CHECK OPTION
ENCRYPTION
SCHEMABINDING
VIEW_METADATA]
In order to delete a view, the DROP VIEW statement is used. The syntax for the DROP VIEW statement is as follows:
The syntax for creating an index is as follows:
In order to create an XML index, the following syntax is used:
Modifications can be made to an existing index by using the ALTER INDEX statement.
In order to specify rebuild options for an index or to enable an index, the following syntax is used:
{
REBUILD WITH rebuild options
}
In order to disable an index, the following syntax is used:
{
DISABLE
}
In order to drop an index, the DROP INDEX statement is used.
- PRIMARY KEY constraint
- FOREIGN KEY constraint
- UNIQUE constraint
- CHECK constraint
- DEFAULT constraint
- NULL Values
In order to implement a constraint on a column while creating a table, the following syntax is used:
(
CONSTRAINT constraint_name(column_name)
)
In order to implement a constraint on a column of an existing table, the following syntax is used:
(
CONSTRAINT constraint_name(column_name)
)
- Download practice question and study guide for mcad for exam.
- Click here to download mcp test study guide and practice question.
- Download free practice test for mcpd MCPD exam.
- Pass Microsoft mcpd-enterprise-applications-developer - MCPD Enterprise Applications Developer
- Become Microsoft MCSA 2000 to 2003 certified.
- Get certified in first attempt download mcsa-to-mcse-2003 - MCSA to MCSE-2003 simulation.
- Best exam simulation Microsoft mcse-2003 download free trial.
- Pass Microsoft mcts-microsoft-visual-studio-2008 - MCTS Microsoft Visual Studio 2008
- Become Microsoft MCTS SQL Server 2005 certified.
- Best exam simulation Microsoft 70-431 download free trial.
- Download practice question and study guide for 70-561-CSHARP for exam.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
