Primary Key:
MySQL allows a primary key on the either of NULL, and NOT NULL declarations.
MSSQL only allows primary keys on fields that are NOT NULL
Date Fields:
MySQL uses a DATE field
MSSQL uses a DATETIME field
Table Creation with AutoIncrement:
MySQL uses keyword AUTO_INCREMENT
example:
CREATE TABLE mytable (
myfield1 integer(12) NOT NULL AUTO_INCREMENT,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);
MSSQL uses keyword IDENTITY(1,1)
example:
CREATE TABLE mytable (
myfield1 int IDENTITY(1,1) NOT NULL,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);
Create Table 'IF NOT EXISTS'
MySQL uses keywords IF NOT EXISTS
example:
CREATE TABLE IF NOT EXISTS mytable (
myfield1 CHAR(9) NOT NULL,
myfield2 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);
MSSQL uses a query into a system table
example:
IF NOT EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytable')
CREATE TABLE mytable (
myfield1 CHAR(9) NOT NULL,
myfield1 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);
More information on autoincrement fields in MSSQL can be found at
an article on http://www.databasejournal.com
No comments:
Post a Comment