CREATE
CREATE TABLE Users
(
PKID Guid NOT NULL PRIMARY KEY,
Username Text (255) NOT NULL,
ApplicationName Text (255) NOT NULL,
Email Text (128) NOT NULL,
Comment VarChar (7) (255),
Password Text (128) NOT NULL,
PasswordQuestion Text (255),
PasswordAnswer Text (255),
IsApproved YesNo,
LastActivityDate DateTime,
LastLoginDate DateTime,
LastPasswordChangedDate DateTime,
CreationDate DateTime,
IsOnLine YesNo,
IsLockedOut YesNo,
LastLockedOutDate DateTime,
FailedPasswordAttemptCount Integer,
FailedPasswordAttemptWindowStart DateTime,
FailedPasswordAnswerAttemptCount Integer,
FailedPasswordAnswerAttemptWindowStart DateTime
)
Creating a Table and setting a constraint
CREATE TABLE NewTableName (FieldName1, TEXT, (FieldName2, TEXT, (FieldName3, DATETIME< CONSTRAINT TableConstraintName UNIQUE (FieldName1, FieldName2, FieldName3) );
DROP TABLE zCUSTOMERS
CREATE TABLE zCUSTOMERS
([CustomerID] NCHAR(5) CONSTRAINT ConstraintName1 PRIMARY KEY
--[CustomerID] NCHAR(5) PRIMARY KEY
--[CustomerID] NCHAR(5) NOT NULL PRIMARY KEY
,[Company Name] NVARCHAR(40)
,ContactName NVARCHAR(30)
,ContactTitle NVARCHAR(30)
,Address NVARCHAR(60) NOT NULL
,City NVARCHAR(15)
,Region NVARCHAR(15)
,PostalCode NVARCHAR(10) CONSTRAINT ConstraintName2 UNIQUE
--,PostalCode NVARCHAR(10) UNIQUE
--,PostalCode NVARCHAR(10) NOT NULL UNIQUE
,Country NVARCHAR(15)
,Phone NVARCHAR(24)
,Fax NVARCHAR(24)
)
DROP TABLE zDATATYPES
CREATE TABLE zDATATYPES
(
TextColumn1 CHAR(10)
,TextColumn2 NCHAR
,TextColumn3 NVARCHAR(20)
,TextColumn4 NTEXT
,TextColumn5 VARCHAR(20)
,TextColumn6 TEXT
,NumberColumn1 BIGINT
,NumberColumn2 DECIMAL
,NumberColumn3 FLOAT
,NumberColumn4 INT
,NumberColumn5 NUMERIC
,NumberColumn6 REAL
,NumberColumn7 SMALLINT
,NumberColumn8 TINYINT
,DateTimeColumn1 DATETIME (DateTime 1 Jan 1753 to 31 Dec 9999 (with milliseconds)
,DateTimeColumn2 SMALLDATETIME (DateTime 1 Jan 1900 to 6 Jun 2079 (with minutes))
,MoneyColumn1 MONEY
,MoneyColumn2 SMALLMONEY
,YesNoColumn1 BIT
,BinaryColumn1 BINARY
,BinaryColumn2 VARBINARY
,TimeStampColumn1 TIMESTAMP
,ImageColumn1 IMAGE
,SQLVariantColumn1 SQL_VARIANT
,UniqueIdentifier1 UNIQUEIDENTIFIER (global unique identifier)
)
DROP TABLE zORDERDETAILS
CREATE TABLE zORDERDETAILS
(OrderID INT CONSTRAINT ConstraintName3 PRIMARY KEY
,ProductID INT REFERENCES Products
'this line only works in SQL Server not Access
,ProductID INT CONSTRAINT ConstraintName4 FOREIGN KEY REFERENCES Products(ProductID)
,UnitPrice MONEY
,Quantity INT
,Discount INT
=--this is an alternative to declaring it all on the same line
--,CONSTRAINT ConstraintName3 PRIMARY KEY (OrderID)
--,CONSTRAINT ConstraintName4 FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
)
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext