SqlServer2012-创建表、删除表 增加字段 删除字段操作
新建表:
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 ,
)
删除表:
Drop table [表名]
插入数据:
INSERT INTO [表名] (字段1,字段2) VALUES (100,\'51WINDOWS.NET\')
删除数据:
DELETE FROM [表名] WHERE [字段名]>100
更新数据:
UPDATE [表名] SET [字段1] = 200,[字段2] = \'51WINDOWS.NET\' WHERE [字段三] = \'HAIWA\'
新增字段:
ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL
删除字段:
ALTER TABLE [表名] DROP COLUMN [字段名]
修改字段:
ALTER TABLE [表名] ALTER COLUMN [字段名] NVARCHAR (50) NULL
重命名表:(Access 重命名表,请参考文章:在Access数据库中重命名表)
sp_rename \'表名\', \'新表名\', \'OBJECT\'
新建约束:
ALTER TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([约束字段] <= \'2000-1-1\')
删除约束:
ALTER TABLE [表名] DROP CONSTRAINT 约束名
新建默认值
ALTER TABLE [表名] ADD CONSTRAINT 默认值名 DEFAULT \'51WINDOWS.NET\' FOR [字段名]
删除默认值
ALTER TABLE [表名] DROP CONSTRAINT 默认值名
删除Sql Server 中的日志,减小数据库文件大小
dump transaction 数据库名 with no_log
backup log 数据库名 with no_log
dbcc shrinkdatabase(数据库名)
exec sp_dboption \'数据库名\', \'autoshrink\', \'true\'
\\\'添加字段通用函数
Sub AddColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Add \"&ColumnName&\" \"&ColumnType&\"\")
End Sub
\\\'更改字段通用函数
Sub ModColumn(TableName,ColumnName,ColumnType)
Conn.Execute(\"Alter Table \"&TableName&\" Alter Column \"&ColumnName&\" \"&ColumnType&\"\")
End Sub
\\\'检查表是否存在
sql=\"select count(*) as dida from sysobjects where id = object_id(N\'[所有者].[表名]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1\"
set rs=conn.execute(sql)
response.write rs(\"dida\")\'返回一个数值,0代表没有,1代表存在
判断表的存在:
select * from sysobjects where id = object_id(N\'[dbo].[tablename]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1
某个表的结构
select * from syscolumns where id = object_id(N\'[dbo].[你的表名]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1
create table student(
Sno int not null primary key,
Sname char(10)not null,
Ssex bit not null,
Sage tinyint not null,
Sdept char(20) not null)
create table course(
Cno int not null primary key,
Cname char(20)not null,
Cpno int not null,
Ccredit tinyint not null)
create table sc(
Sno int not null,
Cno int not null,
Grade tinyint not null
foreign key(Sno)references student(Sno)
foreign key(Cno)references course(Cno)
)
(1)
seleCt top 1 S.sno,sname
from SC,S
where Cno='C2' and SC.sno=S.sno
order by grade desC;
(2)
seleCt sname,age
from Student,SC
where SC.sno not in(
seleCt SC.sno
from SC
where Cno='C2' )and SC.sno=S.sno;
(3)
seleCt sno, avg(grade) as average
from SC
group by sno
having(avg(grade)>80);
(3)法二
seleCt sno, avg(grade) ' average'
from SC
group by sno
having(avg(grade)>80);
(4)
delete from SC
where SC.sno in(
seleCt sno
from S
where sname='S5');
(5)
seleCt sname
from S
where sdept='英语'and sex='男';
(6)
seleCt SC.sno,avg(grade) as average
from S,SC
where S.sno=SC.sno
group by SC.sno;
SqlServer2012-创建表、删除表 增加字段 删除字段操作的更多相关文章
- C#创建、读写、增加、删除XML操作
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- mysql 怎么给一个表一次增加多个字段, mysql 添加 多个 字段
sql 语句: ALTER TABLE oversea_liveauctioneers_detail_info_2018 ADD `result` LONGTEXT, ADD `buyer_premi ...
- Sqlserver2012 使用sql语句增加(或删除)表一个字段
前言 Mark在SqlServer 2012 的数据库使用sql语句增加(或删除)一张表的一个字段. 使用Sql语句增加表的一个字段 [1]语法: alter table table_name add ...
- sql 创建表、删除表 增加字段 删除字段操作
下面是Sql Server 和 Access 操作数据库结构的常用Sql,希望对你有所帮助. 新建表:create table [表名]([自动编号字段] int IDENTITY (1,1) PRI ...
- oracle删除表字段和oracle表增加字段
这篇文章主要介绍了oracle表增加字段.删除表字段修改表字段的使用方法,大家参考使用吧 添加字段的语法:alter table tablename add (column datatype [d ...
- Mysql 修改数据库,mysql修改表类型,Mysql增加表字段,Mysql删除表字段,Mysql修改字段名,Mysql修改字段排列顺序,Mysql修改表名
对于已经创建好的表,尤其是已经有大量数据的表,如果需要对表做一些结构上的改变,我们可以先将表删除(drop),然后再按照新的表定义重建表.这样做没有问题,但是必然要做一些额外的工作,比如数据的重新加载 ...
- Android GreenDAO 3.0 不修改版本号的情况下增加、删除表、添加字段
最近项目中使用了GreenDAO的3.0以上的版本,出现需要增加删除表的需求,刚开始用,发现官方对增加和删除的方法是每次去修改数据库版本号,版本一旦升级,那么原来数据库中的表会全部删除再重建.太麻烦, ...
- Oracle创建表、删除表、修改表(添加字段、修改字段、删除字段)语句总结
创建表: create table 表名 ( 字段名1 字段类型 默认值 是否为空 , 字段名2 字段类型 默认值 是否为空, 字段名3 字段类型 默认值 是否为空, ...... ); 创建一个us ...
- mysql——修改表名、修改字段名、修改字段数据类型、增加字段、删除字段、修改字段排列位置、修改存储引擎、删除表 (示例)
一.创建表和插入数据: ), mz ), bz ) ); ,'sww','sww01'); ,'aww','aww02'); ,'qww','qww03'), (,'eww','eww04'), (, ...
- Oracle创建表、删除表、修改表、字段增删改 语句总结
创建表: create table 表名 ( 字段名1 字段类型 默认值 是否为空 , 字段名2 字段类型 默认值 是否为空, 字段名3 字段类型 默认值 是否为空, ...... ); 创建一个us ...
随机推荐
- 织梦dedecms 扩展channel栏目标签 获取交叉栏目名称和链接
channel栏目标签默认有调用顶级栏目(top).子栏目(son).同级栏目(self),那想获取交叉栏目的名称和链接怎么获取呢? 其实在原来的代码上改一下就可以了.下面是具体代码.打开文件chan ...
- 转战github了
现在已经改在github写博客了,地址为http://connorzhangxu.github.io/ 博客园用了几年,总体感觉不错,但是对公式的支持整体不是很好,所以后来自己搭建了github博客, ...
- Mac系统给移动硬盘分区(图文)
刚买的硬盘500G 准备分几个区 移动硬盘分区格式化有3中形式: 1.Mac OS 扩展日志 格式 此格式mac专用,这种格式的硬盘在PC上不可见,可以用来给 Time Machine 备份, T ...
- Java_异常_01_org.apache.commons.lang.exception.NestableRuntimeException
异常信息: The type org.apache.commons.lang.exception.NestableRuntimeException cannot be resolved. It is ...
- LeetCode:Add Digits - 非负整数各位相加
1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...
- phpunit手动配置
phpunit: #!D:\xampp\php\.\php.exe<?php/* PHPUnit * * Copyright (c) 2001-2013, Sebastian Bergmann ...
- ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)
Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...
- RTSP协议分析(二)
以下是某省IPTV的RTSP协商过程: DESCRIBE rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1& ...
- Oracle 12C 新特性之在线重命名、迁移活跃的数据文件
Oracle 数据库 12c 版本中对数据文件的迁移或重命名不再需要太多繁琐的步骤,可以使用 ALTER DATABASE MOVE DATAFILE 这样的 SQL 语句对数据文件进行在线重命名和移 ...
- spring扩展点之四:Spring Aware容器感知技术,BeanNameAware和BeanFactoryAware接口,springboot中的EnvironmentAware
aware:英 [əˈweə(r)] 美 [əˈwer] adj.意识到的;知道的;觉察到的 XXXAware在spring里表示对XXX感知,实现XXXAware接口,并通过实现对应的set-XXX ...