search
HomeDatabaseMysql Tutorial数据库--添加字段语句

数据库--添加字段语句

Jun 07, 2016 pm 04:12 PM
altertableFielddatabaseAdd toTable NamestatementUniversal

通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 实例: alter table 班级表2 add COLUMN 小组 int 0 以下例子可能确实column alter table [表名] add 字段名 smallint default 0 增加数字字段,整型,缺省值为0 alte

通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数

实例:

 

alter table 班级表2 add  COLUMN 小组 int 0

以下例子可能确实column

 

alter table [表名] add 字段名 smallint default 0 增加数字字段,整型,缺省值为0

alter table [表名] add 字段名 int default 0 增加数字字段,长整型,缺省值为0

 

alter table [表名] add 字段名 single default 0 增加数字字段,单精度型,缺省值为0

 

alter table [表名] add 字段名 double default 0 增加数字字段,双精度型,缺省值为0

 

alter table [表名] add 字段名 Tinyint default 0 增加数字字段,字节型,缺省值为0

 

alter table [表名] add 字段名 text [null] 增加备注型字段,[null]可选参数

alter table [表名] add 字段名 memo [null] 增加备注型字段,[null]可选参数

alter table [表名] add 字段名 varchar(N) [null] 增加变长文本型字段大小为N(1~255)

alter table [表名] add 字段名 char [null] 增加定长文本型字段大小固定为255

 

alter table [表名] add 字段名 Datetime default 函数增加日期型字段,其中函数可以是 now(),date()等,表示缺省值

(上面都是最常用的,还有其他的属性,可以参考下面的数据类型描述)

删除字段: alter table [表名] drop 字段名

修改变长文本型字段的大小:alter table [表名] alter 字段名 varchar(N)

删除表: drop table [表名]

创建表:

 

sql="CREATE TABLE [表名] ([字段1,并设置为主键] int IDENTITY (1, 1) NOT NULL CONSTRAINT PrimaryKey PRIMARY KEY,"&

  "[字段2] varchar(50),"&

  "[字段3] single default 0,"&

  "[字段4] varchar(100) null,"&

  "[字段5] smallint default 0,"&

  "[字段6] int default 0,"&

  "[字段7] date default date(),"&

  "[字段8] int default 1)"

  conn.execute sql

  有null 的表示字段允许零长

Statement
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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment