Creada el: 28/09/98 - Actualizada el: 28/09/98
CREATE PROCEDURE Statement
Creates a stored procedure (a precompiled collection of SQL statements
that can take and/or return
user-supplied parameters.
CREATE PROCedure [<owner>.] procedure_name [;<number>]
[(<parameter1> [, <parameter2>]...[<parameter255>])]
[{FOR REPLICATION} | {WITH RECOMPILE}
[{[WITH] | [,]} ENCRYPTION]]
AS <sql_statements>
CREATE RULE Statement
Creates an object called a rule, which, when bound to a column or a
user-defined datatype, specifies the acceptable values that can be inserted
into that column.
CREATE RULE [<owner>.]<<rule_name>>
AS <condition_expression>
CREATE SCHEMA Statement
Creates a schema that can be thought of as a conceptual container object,
which is the definition of the database without any data in it.
CREATE SCHEMA
[AUTHORIZATION <owner>]
[<schema_element1> [<schema_element2> [...<schema_elementn>]]]
CREATE TABLE Statement
Creates a new table.
CREATE TABLE [<database>.[<owner>].]<table_name>
{<col_name> <column_properties> [<constraint> [<constraint>
[... <constraint>]]]
| [[,] <constraint>]}
[[,] {<next_col_name> |
<next_constraint>}...]
[ON <segment_name>]
<column_properties> =
<datatype> [NULL | NOT NULL | IDENTITY[(<seed>, <increment>)]]
<constraint> =
For a PRIMARY KEY constraint:
[CONSTRAINT <constraint_name>]
PRIMARY KEY [CLUSTERED | NONCLUSTERED]
(<col_name> [, <col_name2> [..., <col_name16>]])
[ON <segment_name>]
For a UNIQUE constraint:
[CONSTRAINT <constraint_name>]
UNIQUE [CLUSTERED | NONCLUSTERED]
(<col_name> [, <col_name2> [..., <col_name16>]])
[ON <segment_name>]
For a FOREIGN KEY constraint:
[CONSTRAINT <constraint_name>]
[FOREIGN KEY (<col_name> [, <col_name2>
[..., <col_name16> ]])]
REFERENCES [<owner>.]<ref_table> [(<ref_col>
[, <ref_col2> [..., <ref_col16>]])]
For a DEFAULT constraint:
[CONSTRAINT <constraint_name>]
DEFAULT {<constant_expression> | <niladic-function> | NULL}
[FOR <col_name>]
For a CHECK constraint(s):
[CONSTRAINT <constraint_name>]
CHECK [NOT FOR REPLICATION] (<expression>)
CREATE TRIGGER Statement
Creates a trigger, a special kind of stored procedure that is executed
automatically when a user attempts the specified data-modification
statement on the specified table.
CREATE TRIGGER [<owner>.]<<trigger_name>>
ON [<owner>.]<table_name>
FOR {INSERT, UPDATE, DELETE}
[WITH ENCRYPTION]
AS <sql_statements>
Or, using the IF UPDATE clause:
CREATE TRIGGER [<owner>.]<<trigger_name>>
ON [<owner>.]<table_name>
FOR {INSERT, UPDATE}
[WITH ENCRYPTION]
AS
IF UPDATE (<column_name>)
[{AND | OR} UPDATE (<column_name>)...] <sql_statements>
CREATE VIEW Statement
Creates a virtual table that represents an alternative way of looking at
the data in one or more tables. You can use views as security mechanisms
by granting permission on a view but not on underlying tables.
CREATE VIEW [<owner>.]<view_name>
[(<column_name> [, <column_name>]...)]
[WITH ENCRYPTION]
AS <select_statement> [WITH CHECK OPTION]
Cursors
Server cursors allow individual row operations to be performed on a
given results set or on the entire set. In SQL Server 6.0, ANSI SQL
cursors are server-based.
DECLARE Statement Defines a cursor.
OPEN Statement Opens a declared cursor.
FETCH Statement Retrieves a specific row from the cursor.
FETCH [[NEXT | PRIOR | FIRST | LAST | ABSOLUTE
{n | @nvar} | RELATIVE {n | @nvar}]
FROM] cursor_name
[INTO @variable_name1, @variable_name2,...]
CLOSE Statement Closes an open cursor.
DEALLOCATE Statement Removes the cursor data structures.
Datatypes
Datatypes specify the data characteristics of columns, stored-procedure
parameters, and local variables.
Binary binary[(<n>)]
varbinary[(<n>)]
Character char[(<n>)]
varchar[(<n>)]
Date and time datetime
smalldatetime
Exact numeric decimal[(<p>[, <s>])]
numeric[(<p>[, <s>])]
Approximate numeric float[(<n>)]
real
Integer int
smallint
tinyint
Monetary money
smallmoney
Special bit
timestamp
user-defined datatypes
Text and image text
image
Synonyms binary varying for varbinary
char varying for varchar
character for char
character for char(1)
character(<n>) for char(<n>)
character varying(<n>) for varchar(<n>)
dec for decimal
double precision for float
float[(<n>)] for n = 1-7 for real
float[(<n>)] for n = 8-15 for float
integer for int
DBCC Statement
Used to check the logical and physical consistency of a database, check
memory usage, decrease the size of a database, check performance
statistics, and so on. DBCC is the SQL Server Database Consistency
Checker.
DBCC {
CHECKALLOC [(<database_name> [, NOINDEX])] |
CHECKCATALOG [(<database_name>)] |
CHECKTABLE (<table_name> [, NOINDEX | <index_id>]) |
CHECKDB [(<database_name> [, NOINDEX])] |
CHECKIDENT[(<table_name>)] |
DBREINDEX([<databases>.<owner>.<table_name>[, <index_name>
[, fillfactor [,{SORTED_DATA | SORTED_DATA_REORG}]]]]
DBREPAIR (<database_name>, DROPDB) [, NOINIT]) |
<dllname> (FREE) |
INPUTBUFFER (<spid>) |
MEMUSAGE |
NEWALLOC [(<database_name> [, NOINDEX])] |
OPENTRAN ({<database_name>} | {<database_id>})
[WITH TABLERESULTS] |
OUTPUTBUFFER (<spid>) |
PERFMON |
PINTABLE (<database_id>, <table_id>) |
PROCCACHE |
SHOW_STATISTICS (<table_name>, <index_name>) |
SHOWCONTIG (<table_id>, [<index_id>]) |
SHRINKDB (<database_name> [, <new_size> [, 'MASTEROVERRIDE']]) |
SQLPERF ({IOSTATS | LRUSTATS | NETSTATS | RASTATS [, CLEAR]} |
{THREADS} | {LOGSPACE}) |
TEXTALL [({<database_name> | <database_id>}[, FULL | FAST])] |
TEXTALLOC [({<table_name> | <table_id>}[, FULL | FAST])] |
TRACEOFF (<trace#>) |
TRACEON (<trace#>) |
TRACESTATUS (<trace#> [, <trace#>...]) |
UNPINTABLE (<database_id>, <table_id>) |
UPDATEUSAGE ({0 | <database_name>} [, <table_name>
[, <index_id>]]) [WITH COUNT_ROWS] |
USEROPTIONS}
[WITH NO_INFOMSGS]
DEALLOCATE Statement
Removes the cursor data structures. DEALLOCATE is different from CLOSE
in that a closed cursor can be re-opened. DEALLOCATE releases all data
structures associated with the cursor and removes the definition of the
cursor.
DEALLOCATE <cursor_name>
Por Luis Walter Reynoso para Ethek & Friends