sql(2):表的简单熟悉操作

本文介绍在MySQL和SQL Server中如何实现ID字段自增,以及如何判断表和特定字段是否存在。涵盖不同数据库系统的具体操作命令,适用于数据库管理与维护场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、设置id自增

mysql:

alter table ndzp_personal_goal change id id int not null auto_increment ; 

sqlserver:

只能在创建表时候创建

alter table t_people add id int identity(1,1)

二、判断表是否存在

mysql:

SELECT count(1) information_schema.TABLES WHERE table_name ='表名';

sqlserver:

select  count(*)  from  dbo.sysobjects where name=  'table_name';

三、判断字段是否存在

mysql:

select count(*) from information_schema.columns where table_name = '表名' and column_name = '字段名'

sqlserver:

select  count(*)  from syscolumns where id=object_id(‘table_name’)  and name=  'column_name';

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值