MySql 建表、添加字段、修改字段、添加索引SQL語句寫法及SQL索引


---------添加索引方法---------
1.添加PRIMARY KEY(主鍵索引)
mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )
2.添加UNIQUE(唯一索引)
mysql>ALTER TABLE `table_name` ADD UNIQUE (
`column`
)

3.添加INDEX(普通索引)
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column` )


4.添加FULLTEXT(全文索引)
mysql>ALTER TABLE `table_name` ADD FULLTEXT (
`column`
)

5.添加多列索引
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )

https://www.cnblogs.com/bk7788/p/6050184.html

 

查看表的索引:
show index from table_name(表名)
https://blog.csdn.net/superdangbo/article/details/79283752

 SQL Server索引

--刪除索引
if exists(select name from sysindexes where name = 'suoyin')
drop index temp.suoyin ---如果存在這個名字的索引,則刪除這個索引
create nonclustered index suoyin_name on temp(Name)

--主鍵,加聚集索引
ALTER TABLE [dbo].[FcyOrder] ADD  CONSTRAINT [PK_FcuencyOrder] PRIMARY KEY CLUSTERED (
    [FreqOrderId] ASC
)
go

CREATE NONCLUSTERED INDEX [IX_Code] ON [dbo].[Fct_Product] ([ProductCode]) ON [PRIMARY]
GO

CREATE INDEX [IX_OrderId] ON [dbo].[FncyOrder]
([OrderId] ASC)
GO

CREATE INDEX [IDX_Disabled_ChanyCodeAndName] ON [dbo].[Fcommodity]
([Disabled] ASC) 
INCLUDE ([ChadityCode], [ChaodityName]) 
GO

CREATE UNIQUE INDEX [IDX_SiteWarehouseAndSerialNumber] ON [dbo].[FcquestInfo]
([SerialNumber] ASC, [SiouseId] ASC) 
WITH (IGNORE_DUP_KEY = ON)
GO

CREATE UNIQUE INDEX [IX_tockFove_FoveNo] ON [dbo].[TockFove]
([FveNo] ASC) 
WITH (IGNORE_DUP_KEY = ON)
GO

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM