Some SQL statements often used in work and study

黄舟
Release: 2017-02-20 11:46:33
Original
1110 people have browsed it

[Introduction] Some commonly used SQL statements: Create a new table:

CREATE table [表名] ( [自动编号字段] int IDENTITY (1,1) PRIMARY KEY , [字段1] nVarChar(50) default 默认值 null , [字段2] ntext null , [字段3] d
Copy after login

Some commonly used SQL statements:

Create a new table:

create table [表名] ( [自动编号字段] int IDENTITY (1,1) PRIMARY KEY , [字段1] nVarChar(50) default '默认值' null , [字段2] ntext null , [字段3] datetime, [字段4] money null , [字段5] int default 0, [字段6] Decimal (12,4) default 0, [字段7] image null , )
Copy after login
Copy after login

Create a new table:

create table [表名] ( [自动编号字段] int IDENTITY (1,1) PRIMARY KEY , [字段1] nVarChar(50) default '默认值' null , [字段2] ntext null , [字段3] datetime, [字段4] money null , [字段5] int default 0, [字段6] Decimal (12,4) default 0, [字段7] image null , )
Copy after login
Copy after login

Delete table:

Drop table [table name]


Insert data:

INSERT INTO [表名] (字段1,字段2) VALUES (100,'51WINDOWS.NET')
Copy after login

Delete data:

DELETE FROM [表名] WHERE [字段名]>100
Copy after login

Update data:

UPDATE [表名] SET [字段1] = 200,[字段2] = '51WINDOWS.NET' WHERE [字段三] = 'HAIWA'
Copy after login

New field:

ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL
Copy after login

Delete field:

ALTER TABLE [表名] DROP COLUMN [字段名]
Copy after login

Modify field:

ALTER TABLE [表名] ALTER COLUMN [字段名] NVARCHAR (50) NULL
Copy after login

Rename table: (Access renames the table, please refer to the article: Rename the table in the Access database)

sp_rename 'Table name', 'New table name', 'OBJECT '


New constraint:

ALTER TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([约束字段] <= '2000-1-1')
Copy after login

Delete constraint:

ALTER TABLE [表名] DROP CONSTRAINT 约束名
Copy after login

New default Value

ALTER TABLE [表名] ADD CONSTRAINT 默认值名 DEFAULT '51WINDOWS.NET' FOR [字段名]
Copy after login

Delete default value

ALTER TABLE [表名] DROP CONSTRAINT 默认值名
Copy after login

The above is the content of some SQL statements often used in work and study, more For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!