用SQL语句修改SQL表结构
最近修改数据库已经存在的表结构,发现用SQL语句能很好的修改表的结构。SQL数据库记录数非常庞大,如果想修改表的字段类型,使用企业管理器来更改字段类型,很多时候会超时,更改不成功,这个时候,可以用SQL语句来更改,以下为相应的代码实例:
1.更改字段类型长度
alert table 表 alert column 字段名 类型的长度
eg: alter table users alter column IDcard char(20)
2.更改字段类型
alert table 表 alert column 字段名 更改后的类型
eg:把城市表的城市名字段由原来的varchar改成int
alert table testcity alter column cityname int
3.添加not null约束
alert table 表alert column 字段名 int not null
4.设置主键
alert table 表 add constraint 主键名 primary key(字段名)
5.更改字段名
EXEC sp_name '表名.字段名‘,更改后的字段名,’COLUMN‘
6.添加字段名
alert table 表 add 字段名 字段类型 default null
相关文档:
D:\projects\openi\misc\xxxx_data_20090828>bcp [xxxxolap].[dbo].[wdb_cxbz] in wdb_xxx.txt -c -T
SQLState = 37000, NativeError = 4060
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "xxxolap" requested by the login. The login failed.
S ......
update t1 set t1.value=t2.value from t2 where t1.id=t2.id
update jbsite_class set topicnum = count
from (select t2.classid,count from (
select distinct classid,count(*) as count
from jbsite_product ......
一、Orcale 时的查询
String hql = "from SmsTemplate t where 1=1 ";
if (model != null && !"".equals(model.getEndTimes())&& null!=model.getEndTimes() ) {
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //格式化当前系统日期
Date ......
ALTER PROCEDURE [dbo].[GetUsersList]
@BigClassID int=0,--大类别ID
@SmallClassID int=0 ,--小类别ID
@pageindex int=1,
@pagesize int=3,
@ret int output --共几条
AS
set rowcount @pagesize
if @SmallClassID>0
begin
select * from(
select id,BigClassName,SmallClassName,UserName,Corporation,r ......
createdb.bat文件
@echo off
echo ╬ ╱◥███◣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬
echo ╬ ︱田︱田 田 ︱ ......