Wednesday, April 16, 2008

SQL KEYS

Get Day from DATE:
SELECT DAY(GETDATE())

How to get the version of SQL Server
SELECT @@VERSION AS 'SQL Server Version'
---------------------------------------------------------------------------
Be aware that there are often subtle syntax variations between different database systems. Also other key properties (for example 'clustered') will vary between database systems. Therefore please treat this part of the SQL crib sheet as a guide only.

Create a primary key on a table:
Alter Table TheTable Add Primary Key (field1, field2)
To add an index on a field:

alter table TableName Add Index (field1)
To remove a primary key:

alter table drop primary key

No comments: