What to use instead of "Key" for SQL Server?
I have a script of MySQL queries that I am using and that are working.
I am trying to execute the same queries on a Microsoft SQL Server and there is one thing that I do not understand.
MySql uses "key" to define a key made up of different fields.
How do I do the same in SQL Server?
Thank!
-Adeena
source to share
In MySQL, the keyword KEY
is just synonymous INDEX
. The following two are equivalent:
CREATE TABLE foo (
id SERIAL PRIMARY KEY,
ctime DATETIME,
KEY ctkey (ctime)
);
CREATE TABLE foo (
id SERIAL PRIMARY KEY,
ctime DATETIME,
INDEX ctidx (ctime)
);
In Microsoft SQL Server, the closest equivalent INDEX
. As far as I can tell, to create an index on a column in Microsoft SQL Server you are using CREATE INDEX
. You can also create constraints that create indexes as part of the statement CREATE TABLE
, but if you just need the index, use CREATE INDEX
.
CREATE TABLE foo (
id BIGINT IDENTITY PRIMARY KEY,
ctime DATETIME
);
CREATE INDEX ctidx ON foo(ctime);
See also the documentation for CREATE INDEX
.
source to share