pymssql·ÃÎÊsqlserverµÄÒ»¸öbug
¡¡¡¡¶ÔÊý¾Ý¿â½øÐжà±í²Ù×÷£¬Èç¹û±íÓë±íÖ®¼ä´æÔÚÒÀÀµ£¬ÄÇôÏÔʽµÄʹÓÃÊÂÎñ£¬¿ÉÒÔ±£³Ö¶ÔÊý¾Ý¿â²Ù×÷µÄÔ×ÓÐÔ¡£ÓÃPython·ÃÎÊSqlServerÊý¾Ý¿â£¬ÎÒʹÓÃpymssql¿â¡£½ñÌìÔÚʹÓÃÕâ¸ö¿âµÄʱºò£¬·¢ÏÖÒ»¸öÎÊÌâ¡£
ÎÊÌâ´ó¸ÅÊÇÕâÑùµÄ£º
¡¡¡¡ÎÒÓÐÁ½ÕÅ±í£¬Ò»ÕÅÖ÷±í£¨ClassInfo£©£¬Ò»ÕÅ´Ó±í£¨Student£©£¬Student±íͨ¹ýÍâ¼üClassIDÓëClassInfo±í½øÐйØÁª¡£ÕâÁ½ÕűíµÄÖ÷¼ü¶¼ÊÇ×ÔÔöÐ͵ÄintÐÍ×ֶΡ£
¡¡¡¡´´½¨±íµÄSQLÓï¾äÈçÏ£º
CREATE TABLE ClassInfo(
ClassID INT IDENTITY(1, 1) PRIMARY KEY,
ClassName VARCHAR(20) NOT NULL
)
GO
CREATE TABLE Student(
StudentID INT IDENTITY(1, 1) PRIMARY KEY,
ClassID INT NOT NULL,
StudentName VARCHAR(20) NOT NULL,
FOREIGN KEY (ClassID) REFERENCES ClassInfo(ClassID)
)
GO
¡¡¡¡ÔÚ´úÂëÖУ¬ÏÈ´´½¨Ò»¸ö°à¼¶£¬È»ºóÔڰ༶ÖвåÈëѧÉúÊý¾Ý¡£Èç¹ûÕâÁ½¸ö²Ù×÷ÔÚÒ»¸öÊÂÎñÖÐÍê³É£¬Ò»°ãÇé¿öÏ£¬°´ÕÕpymssqlÌṩµÄÎĵµ£¬ÎÒÃÇ»áдÕâÑùµÄÓï¾äÀ´ÊµÏÖ£º
import pymssql
conn = pymssql.connect(host = 'JGood\\SQLEXPRESS', database = "Study",
user = "sa", password = "sa")
cur = conn.cursor()
#ÍùÖ÷±íÖÐÌí¼ÓÒ»Ìõ¼Ç¼
cur.execute("INSERT INTO [ClassInfo] ([ClassName]) VALUES (%s)", 'jk0403')
#»ñÈ¡ID¡£
cur.execute("SELECT @@identity as ID")
classID = cur.fetchone()[0]
#Íù´Ó±íÖÐÌí¼Ó¼Ç¼
cur.execute("INSERT INTO [Student] (ClassID, StudentName) VALUES (%d, %s)",
(classID, 'JGood'))
conn.commit()
cur.close()
conn.close()
¡¡¡¡µ«ÊǺÜÒź¶£¬ÔÚÔËÐдúÂëµÄʱºò£¬³ö´íÁË£º
¡¡¡¡Èç¹ûÎÒ°ÑÉÏÃæµÄ²Ù×÷·Ö³ÉÁ½¸ö¶ÀÁ¢µÄÊÂÎñÀ´ÊµÏÖ£¬·¢ÏÖÊÇûÓÐÎÊÌâµÄ¡£
¡¡¡¡¾¹ýÒ»ÏÂÎçµØÃþË÷£¬ÖÕËãÕÒµ½Ò»¸ö½â¾ö°ì·¨£¬¾ÍÊÇ°Ñ×ÔÔöµÄIDÒÔÆ´×Ö·û´®µÄÐÎʽÌí¼Óµ½SQLÓï¾äÀ¶ø²»ÊÇÒÔSQL²ÎÊýµÄÐÎʽ¡£
#Íù´Ó±íÖÐÌí¼Ó¼Ç¼
cur.execute("INSERT INTO [Student] (ClassID, StudentName) VALUES (" + str(classID) + ", %s)", ('JGood', ))
¡¡¡¡ÎÒ²»ÖªµÀÕâËã²»ËãÊÇpymssqlµÄÒ»¸öbug£ºÔÚÒ»¸öÊÂÎñÖУ¬¶ÔÓÚ×Ô¶¯Éú³ÉµÄÍâ¼üÖµ£¬²»ÄÜÒÔSQL²ÎÊýµÄÐÎʽ²åÈëÊý¾Ý¿â¡£
Ïà¹ØÎĵµ£º
SQLServerºÍOracleµÄ³£Óú¯Êý¶Ô±È
¡¡¡¡1.¾ø¶ÔÖµ
¡¡¡¡S:select abs(-1) value
¡¡¡¡O:select abs(-1) value from dual
¡¡¡¡2.È¡Õû(´ó)
¡¡¡¡S:select ceiling(-1.001) value
¡¡¡¡O:select ceil(-1.001) value from dual
¡¡¡¡3.È¡Õû£¨Ð¡£©
¡¡¡¡S:select floor(-1.001) value
¡¡¡¡O:select floor(-1.001) valu ......
Oracle±Ê¼Ç
l ¹ØÓÚTRUNCº¯Êý
SELECT
RELATED_ID ,
DOC_ID ,
CAT_ID ,
CAT_CODE ,
RELEASE_DATE ,
&n ......
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLÏ°¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
SQLserver×Ö·û´®·Ö¸îº¯Êý
Ò»¡¢°´Ö¸¶¨·ûºÅ·Ö¸î×Ö·û´®£¬·µ»Ø·Ö¸îºóµÄÔªËظöÊý£¬·½·¨ºÜ¼òµ¥£¬¾ÍÊÇ¿´×Ö·û´®ÖдæÔÚ¶àÉÙ¸ö·Ö¸ô·ûºÅ£¬È»ºóÔÙ¼ÓÒ»£¬¾ÍÊÇÒªÇóµÄ½á¹û¡£
CREATE function Get_StrArrayLength
(
@str varchar(1024), --Òª·Ö¸îµÄ×Ö·û´®
@split varchar(10) --·Ö¸ô·ûº ......