直接从SQL语句问题贴子数据建表并生成建表语句的存储过程数据库教程
“恐龙崽滚蛋中”通过精心收集,向本站投稿了3篇直接从SQL语句问题贴子数据建表并生成建表语句的存储过程数据库教程,下面是小编整理后的直接从SQL语句问题贴子数据建表并生成建表语句的存储过程数据库教程,希望能帮助到大家!
篇1:直接从SQL语句问题贴子数据建表并生成建表语句的存储过程数据库教程
存储过程|数据|问题|语句
下面的存储过程,可帮你在回答SQL语句问题时,直接从贴子的样本数据建表并生成建表语句,省去大量的手工输入数据的工作,
/*Create Table from your web page data
* -JAN-1, OpenVMS,V0.1
* 2004-JAN-2, V0.5, add tab & blank values logical
* 2004-JAN-3, V1.0, add SQL Statement generation
* 2004-JAN-4, V1.1, fix datatype like decimal(4,2) bug
* 2004-JAN-4, V1.2, fix field name bug
*
* Sample Call: in SQL Query Analyzer
exec dbo.create_table '##t2','varchar(20),datetime k','
ID AnDate
99101 -11-24 00:00:00.000
99101 -11-15 00:00:00.000
99101 2003-11-29 00:00:00.000
99101 2003-12-20 00:00:00.000'
注意:
1 如用临时表名,只能用全局临时表 ##,否则不可访问
2 如果没有列名,则需要在第一行数据手动加上列名
3 字段名称不允许含空格
4 至少一行数据,否则没有意义
5 字段值为空需要写上NULL,字段值中的任何符号作为值的一部分
6 没有对定义类型和值的类型匹配检查
7 可指定值中含有空格,方法为在该类型定义中的尾部加字母 k, 如 datatime k,
8 如过值中含有单引号,需要复写 ' -》''
*/
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'create_table'
AND type = 'P')
DROP PROCEDURE create_table
go
create proc dbo.create_table
@table_name varchar(60),--- Table name
@datatype varchar(1000),--- separated by comma ','
@str nvarchar(3000) --- input string pasted from web page
AS
BEGIN
declare @dt table(id int identity(1,1),fld_name varchar(30),fld_type varchar(20),blank int)
declare @sqlt table(sql_statement varchar(8000))
declare @tmp varchar(1000),@num1 int,@num2 int,@sql nvarchar(4000)
declare @a nvarchar(3000),@i int,@j int,@k int,@m int,@x nvarchar(1000)
SET NOCOUNT ON
if object_id(@table_name) is not null
begin
set @a='TABLE '+@table_name+' exists,choose a new one!'
RAISERROR (@a,16,1)
return
end
--提取类型名
set @datatype=lower(replace(@datatype,' ',''))
set @tmp=@datatype
set @i=1
set @num1=0
while @i>0
begin
select @i=charindex(',',@datatype)
--check datatype like decimal(10,4)
if @i>charindex('(',@datatype) and @i set @i=charindex(')',@datatype)+1 select @j=charindex('k',@datatype) set @m=0 if (@j>1 and @j<@i) or (@i=0 and @j=len(@datatype)) set @m=-1 if @i>1 begin insert into @dt(fld_type,blank) values(left(@datatype,@i-1+@m),case when @m=-1 then 1 else 0 end) select @datatype=right(@datatype,len(@datatype)-@i) end if @i=0 and len(@datatype)>0 insert into @dt(fld_type,blank) values(left(@datatype,len(@datatype)+@m), case when @m=-1 then 1 else 0 end) if @i=1 or len(@datatype)=0 begin RAISERROR ('error data type,comma sign can not be a prefix or surfix',16,1) return end set @num1=@num1+1 end --检查类型 if exists (select fld_type from @dt where (case when charindex('(',fld_type)>0 then left(fld_type,charindex('(',fld_type)-1) else fld_type end) not in (select name from systypes) or charindex('(',fld_type)*charindex(')',fld_type)=0 and charindex('(',fld_type)+charindex(')',fld_type)>0) begin RAISERROR ('error data type.', 16, 1) return end --提取字段和数据 set @a=replace(@str,char(9),' ') --- TAB char set @a=rtrim(ltrim(@a)) if charindex(char(13)+char(10),right(@a,len(@a)-1))=0 or len(@a)=0 begin RAISERROR ('input data error,check your data.', 16, 1) return end if object_id('tempdb.dbo.#xx') is not null drop table #xx select identity(int,1,1) ID,space(50) val into #xx where 1=2 set @k=0 set @num2=0 set @m=0 while len(@a)>0 begin set @i=1 set @x=left(@a,1) if @x=char(10) begin if @m>@num2 and @num2>0 and charindex('k',@datatype)=0 begin RAISERROR ('number of data is greater than the columns,you should add k in data type difinition.', 16, 1) return end set @m=0 end if @x not in (' ',char(13),char(10)) begin set @i=charindex(' ',@a) set @j=charindex(char(13)+char(10),@a) set @m=@m+1 if @k-1 set @k=@k+1 if @j>0 and (@j<@i or @j>@i and substring(@a,@i,@j-@i)=space(@j-@i)) begin set @i=@j if @k>@num2 and @k-1 set @num2=@k set @k=-1 end if @i=0 set @i=(case when @j>0 then @j else len(@a)+1 end) select @j=max(ID) from #xx if @m=1 or @j<=@num1 or (select blank from @dt where ID=@m-1) 1 begin if @j<@num1 set @x='['+replace(rtrim(left(@a,@i-1)),']',']]')+']' else set @x=rtrim(left(replace(@a,'''',''''''),@i-1)) insert into #xx(val) values(@x) end else begin update #xx set val=val+' '+rtrim(left(@a,@i-1)) where ID=@j set @m=@m-1 end end if @i else set @a='' end update #xx set val='' where val='NULL' update #xx set val=''''+val+'''' where ID>@num2 if @num1@num2 begin RAISERROR ('datatype dismatch the columns',16,1) return end -- if use the exists template table,drop it if object_id('tempdb.dbo.'+@table_name) is not null exec('drop table '+@table_name) -- 建表 update a set a.fld_name=b.val from @dt a,#xx b where a.ID=b.ID and a.ID<=@num1 set @a='' select @a=@a+fld_name+' '+fld_type+',' from @dt where ID<=@num1 set @a=left(@a,len(@a)-1) set @sql='create table '+@table_name+'('+@a+')' exec(@sql) insert into @sqlt select @sql --插入数据 set @i=@num1+1 while @i<=(select max(ID) from #xx) begin set @a='' set @sql='select @s=@s+val+'','''+' from (select top '+convert(varchar(10),@num1) +' val from #xx where ID>='+convert(varchar(10),(@i))+') a' exec sp_executesql @sql,N'@s nvarchar(3000) output',@a output set @a=left(@a,len(@a)-1) set @sql='insert into '+@table_name+' select '+@a if len(@a)>0 exec(@sql) insert into @sqlt select @sql set @i=@i+@num1 end select * from @sqlt --select * from @dt exec('select * from '+@table_name) SET NOCOUNT OFF END 测试 exec dbo.create_table '##t2','varchar(20),datetime k',' ID AnDate 99101 2002-11-24 00:00:00.000 99101 2003-11-15 00:00:00.000 99101 2003-11-29 00:00:00.000 99101 2003-12-20 00:00:00.000' 结果 sql_statement -------------------------------------------------------- create table ##t2(ID varchar(20),AnDate datetime) insert into ##t2 select '99101','2002-11-24 00:00:00.000' insert into ##t2 select '99101','2003-11-15 00:00:00.000' insert into ##t2 select '99101','2003-11-29 00:00:00.000' insert into ##t2 select '99101','2003-12-20 00:00:00.000' ID AnDate -------------------- --------------------------- 99101 2002-11-24 00:00:00.000 99101 2003-11-15 00:00:00.000 99101 2003-11-29 00:00:00.000 99101 2003-12-20 00:00:00.000 ORACLE的写法在测试中,
篇2:动态创建SQL Server数据库、表、存储过程数据库教程
server|创建|存储过程|动态|数据|数据库
下面是利用SQL语句创建数据库、表、存储过程、视图、索引、规则、修改表、查看数据等的方法,所要增加的控件如下:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Private ConnectionString As String = “Data Source=.;Initial Catalog=;User Id=sa;Password=;”
Private reader As SqlDataReader = Nothing
Private conn As SqlConnection = Nothing
Private cmd As SqlCommand = Nothing
Private AlterTableBtn As System.Windows.Forms.Button
Private sql As String = Nothing
Private CreateOthersBtn As System.Windows.Forms.Button
#Region “ Windows 窗体设计器生成的代码 ”
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose
End If
End If
MyBase.Dispose(disposing)
End Sub
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents CreateDBBtn As System.Windows.Forms.Button
Friend WithEvents CreateTableBtn As System.Windows.Forms.Button
Friend WithEvents CreateSPBtn As System.Windows.Forms.Button
Friend WithEvents CreateViewBtn As System.Windows.Forms.Button
Friend WithEvents btnAlterTable As System.Windows.Forms.Button
Friend WithEvents btnCreateOthers As System.Windows.Forms.Button
Friend WithEvents btnDropTable As System.Windows.Forms.Button
Friend WithEvents btnViewData As System.Windows.Forms.Button
Friend WithEvents btnViewSP As System.Windows.Forms.Button
Friend WithEvents btnViewView As System.Windows.Forms.Button
Me.CreateDBBtn = New System.Windows.Forms.Button()
Me.CreateTableBtn = New System.Windows.Forms.Button()
Me.CreateSPBtn = New System.Windows.Forms.Button()
Me.CreateViewBtn = New System.Windows.Forms.Button()
Me.btnAlterTable = New System.Windows.Forms.Button()
Me.btnCreateOthers = New System.Windows.Forms.Button()
Me.btnDropTable = New System.Windows.Forms.Button()
Me.btnViewData = New System.Windows.Forms.Button()
Me.btnViewSP = New System.Windows.Forms.Button()
Me.btnViewView = New System.Windows.Forms.Button()
Me.DataGrid1 = New System.Windows.Forms.DataGrid()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'CreateDBBtn
'
Me.CreateDBBtn.Location = New System.Drawing.Point(19, 9)
Me.CreateDBBtn.Name = “CreateDBBtn”
Me.CreateDBBtn.Size = New System.Drawing.Size(104, 23)
Me.CreateDBBtn.TabIndex = 0
Me.CreateDBBtn.Text = “创建数据库”
'
'CreateTableBtn
'
Me.CreateTableBtn.Location = New System.Drawing.Point(139, 9)
Me.CreateTableBtn.Name = “CreateTableBtn”
Me.CreateTableBtn.TabIndex = 1
Me.CreateTableBtn.Text = “创建表”
'
'CreateSPBtn
'
Me.CreateSPBtn.Location = New System.Drawing.Point(230, 9)
Me.CreateSPBtn.Name = “CreateSPBtn”
Me.CreateSPBtn.Size = New System.Drawing.Size(104, 23)
Me.CreateSPBtn.TabIndex = 2
Me.CreateSPBtn.Text = “创建存储过程”
'
'CreateViewBtn
'
Me.CreateViewBtn.Location = New System.Drawing.Point(350, 9)
Me.CreateViewBtn.Name = “CreateViewBtn”
Me.CreateViewBtn.TabIndex = 3
Me.CreateViewBtn.Text = “创建视图”
'
'btnAlterTable
'
Me.btnAlterTable.Location = New System.Drawing.Point(441, 9)
Me.btnAlterTable.Name = “btnAlterTable”
Me.btnAlterTable.TabIndex = 4
Me.btnAlterTable.Text = “修改表”
'
'btnCreateOthers
'
Me.btnCreateOthers.Location = New System.Drawing.Point(17, 43)
Me.btnCreateOthers.Name = “btnCreateOthers”
Me.btnCreateOthers.Size = New System.Drawing.Size(104, 23)
Me.btnCreateOthers.TabIndex = 5
Me.btnCreateOthers.Text = “创建规则和索引”
'
'btnDropTable
'
Me.btnDropTable.Location = New System.Drawing.Point(138, 43)
Me.btnDropTable.Name = “btnDropTable”
Me.btnDropTable.TabIndex = 6
Me.btnDropTable.Text = “删除表”
'
'btnViewData
'
Me.btnViewData.Location = New System.Drawing.Point(351, 43)
Me.btnViewData.Name = “btnViewData”
Me.btnViewData.TabIndex = 7
Me.btnViewData.Text = “查看数据”
'
'btnViewSP
'
Me.btnViewSP.Location = New System.Drawing.Point(230, 43)
Me.btnViewSP.Name = “btnViewSP”
Me.btnViewSP.Size = New System.Drawing.Size(104, 23)
Me.btnViewSP.TabIndex = 8
Me.btnViewSP.Text = “查看存储过程”
'
'btnViewView
'
Me.btnViewView.Location = New System.Drawing.Point(443, 43)
Me.btnViewView.Name = “btnViewView”
Me.btnViewView.TabIndex = 9
Me.btnViewView.Text = “查看视图”
'
'DataGrid1
'
Me.DataGrid1.DataMember = “”
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(20, 76)
Me.DataGrid1.Name = “DataGrid1”
Me.DataGrid1.Size = New System.Drawing.Size(500, 183)
Me.DataGrid1.TabIndex = 10
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(538, 281)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1, Me.btnViewView, _
Me.btnViewSP, Me.btnViewData, Me.btnDropTable, Me.btnCreateOthers, Me.btnAlterTable, _
Me.CreateViewBtn, Me.CreateSPBtn, Me.CreateTableBtn, Me.CreateDBBtn})
Me.Name = “Form1”
Me.Text = “动态创建SQL Server数据库、表、存储过程等架构信息”
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
' 创建数据库
Private Sub CreateDBBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateDBBtn.Click
conn = New SqlConnection(ConnectionString)
' 打开连接
If conn.State ConnectionState.Open Then
conn.Open()
End If
'MyDataBase为数据库名称
Dim sql As String = “CREATE DATABASE MyDataBase ON PRIMARY (Name=MyDataBase_data, filename = ” + _
“'D:\MyDataBase.mdf', size=3,” + “maxsize=5, filegrowth=10%) log on” + “(name=MyDataBase_log, ” + _
“filename='D:\MyDataBase.ldf',size=3,” + “maxsize=20,filegrowth=1)”
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
'创建表
Private Sub CreateTableBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateTableBtn.Click
conn = New SqlConnection(ConnectionString)
' 打开连接
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = “Data Source=.;Initial Catalog=MyDataBase;User Id=sa;Password=;”
conn.ConnectionString = ConnectionString
conn.Open()
sql = “CREATE TABLE myTable” + “(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY,” + _
“myName CHAR(50) NOT Null, myAddress CHAR(255), myValues FLOAT)”
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
' 添加纪录
sql = “INSERT INTO myTable(myId, myName, myAddress, myValues) ” + _
“VALUES (1001, _'【孟宪会之精彩世界】之一', 'xml.sz.luohuedu.net/', 100 ) ”
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = “INSERT INTO myTable(myId, myName, myAddress, myValues) ” + _
“VALUES (1002, '【孟宪会之精彩世界】之二', 'www.erp800.com/net_lover/', 99) ”
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = “INSERT INTO myTable(myId, myName, myAddress, myValues) ” + _
“VALUES (1003, '【孟宪会之精彩世界】之三', 'xml.sz.luohuedu.net/', 99) ”
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = “INSERT INTO myTable(myId, myName, myAddress, myValues) ” + _
“VALUES (1004, '【孟宪会之精彩世界】之四', 'www.erp800.com/net_lover/', 100) ”
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
'创建存储过程
Private Sub CreateSPBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateSPBtn.Click
sql = “CREATE PROCEDURE myProc AS” + “ SELECT myName, myAddress FROM myTable GO”
ExecuteSQLStmt(sql)
End Sub
'创建视图
Private Sub CreateViewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CreateViewBtn.Click
sql = “CREATE VIEW myView AS SELECT myName FROM myTable”
ExecuteSQLStmt(sql)
End Sub
'修改表
Private Sub btnAlterTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnAlterTable.Click
sql = “ALTER TABLE MyTable ADD newCol datetime NOT NULL DEFAULT (getdate())”
ExecuteSQLStmt(sql)
End Sub
'创建规则和索引
Private Sub btnCreateOthers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnCreateOthers.Click
sql = “CREATE UNIQUE INDEX ” + “myIdx ON myTable(myName)”
ExecuteSQLStmt(sql)
sql = “CREATE RULE myRule ” + “AS @myValues >= 90 AND @myValues < 9999”
ExecuteSQLStmt(sql)
End Sub
'删除表
Private Sub btnDropTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnDropTable.Click
Dim sql As String = “DROP TABLE MyTable”
ExecuteSQLStmt(sql)
End Sub
'浏览表数据
Private Sub btnViewData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnViewData.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = “Data Source=.;Initial Catalog=MyDataBase;User Id=sa;Password=;”
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter(“SELECT * FROM myTable”, conn)
Dim ds As New DataSet(“myTable”)
da.Fill(ds, “myTable”)
DataGrid1.DataSource = ds.Tables(“myTable”).DefaultView
End Sub
'浏览存储过程
Private Sub btnViewSP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnViewSP.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = “Data Source=.;Initial Catalog=MyDataBase;User Id=sa;Password=;”
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter(“myProc”, conn)
Dim ds As New DataSet(“SP”)
da.Fill(ds, “SP”)
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
'浏览视图
Private Sub btnViewView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnViewView.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = “Data Source=.;Initial Catalog=MyDataBase;User Id=sa;Password=;”
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter(“SELECT * FROM myView”, conn)
Dim ds As New DataSet()
da.Fill(ds)
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
Private Sub ExecuteSQLStmt(ByVal sql As String)
conn = New SqlConnection(ConnectionString)
' 打开连接
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = “Data Source=.;Initial Catalog=MyDataBase;User Id=sa;Password=;”
conn.ConnectionString = ConnectionString
conn.Open()
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
End Class
篇3:两表连接的SQL语句数据库教程
两表连接的SQL语句:这两种写法哪种好?现在提倡用哪一种呢?
例如:一个二表连接的SQL,有两种写法:
(1)select A.c1,A.c2,B.c1,B.c2
from table1 A,table2 B
where A.id=B.id
(2)select A.c1,A.c2,B.c1,B.c2
from table1 A join table2 B
on A.id=B.id
哪种写法好呢?现在提倡用哪一种?
你喜欢用哪一种?
我习惯用(1)
---这两个哪个好?
其中11楼的回答最为深入,其实这个问题还是有一定的历史原因的,不管你习惯什么样的写法只要知道来龙去脉就不会再被细枝末节来迷惑了。以下观点为个人认识,如有偏差欢迎指正。
简单的说,前者是ansi sql 86标准后者是ansi sql 92标准(*****) ,这个观点最容易被人接受。
什么是ansi?美国国家标准局,iso的重要成员之一,1918年就有了。
什么是ansi sql?就是ansi注意到了sql的生产力,于是规范化了一下。
什么是sql?他是ibm发明的,oracle发扬广大的一门语言。
为什么是两家公司?。
70年代初因为ibm内部各方利益斗争激烈,导致某大牛的研究成果只能以论文方式发表。
70年代末某小公司把此技术用在商业领域就成了oracle,直到n年后ibm db2才出来。
所以,sql不是ansi 发明的,ansi 标准也不能通吃所有数据库平台。
比如下面这个是什么数据库的语法?反正ansi 标准在他那里是报错的。
select * from (a inner join b on a.id=b.id) inner join c on a.id=c.id
那么在ansi86之前的数据库有哪些?oracle和db2是肯定的了,
另外还有一些当时的小角色:Informix,dbase系列等。
而sybase的数据库和SQLServer是86年之后出来的,而前面那个奇怪的join语法的access是90后的。
古老的sqlserver和oracle我都没有用过,反正在02年用oracle8i时还不支持ansi 92的inner join,他是97年生的。一直到本世纪发布的oacle9i 才改了过来。用多了t-sql的人会问 left join咋办,where a.id=b.id(+) 就可以了,人家没那么笨的,t-sql以前还有*=这样的表示。
那么这么看貌似ansi的规范力度不够?其实不是,国际标准化也不可能一刀切,在ansi92 当中定义了4个级别,n多条款。大意就是大家符合入门级就行了,其他高级别仅供参考,甚至iso根本不会验证其他级别..而诸如inner join和left join之类的都是过渡级的,濉
所以我前面打了5个星星的那句话并不是完全正确的,正确的应该是
前者符合ansi 86 标准和ansi 92入门级标准,后者符合ansi92 过渡级标准。
不是oracle8i不符合ansi92,而是没有符合ansi92的高级别规范,而完全实现高级别标准的数据库系统是没有的。
早在oracle7就已经完全符合ansi92了,当然是指入门级,而且他就是ansi92 的模版范例。
--回到上面的话题,这两个哪个好?
性能当然完全一样,区别只是习惯和喜好,但也因为标准级别不同而具有不同的风险。
如果想要优雅而易于维护且不容易写错的代码,当然用高标准的第二种方法。
如果必要考虑风险这个因素,比如涉及到多种平台的迁移或者整合,你应该用第一种,起码在两个表的情况下他还是比较安全的。
----
顺带提一句,ansi标准一直在修订:具体有多少版本就不列举了,我们得到的好处自然是多多的,比如递归、对象、数组、xml等等在各主流数据库的新版本中都陆续实现了
【直接从SQL语句问题贴子数据建表并生成建表语句的存储过程数据库教程】相关文章:






文档为doc格式