root
-
DB 사용자정의 함수기본 사용자정의함수 예제Database/MS-SQL 2008. 10. 16. 11:47
오라클도 보자 저장프로시저와 조금비슷해 보이지만 일반적인 프로그래밍언어에서 사용되는 함수와 같이 복잡한 프로그래밍이 가능 함수는 RETURN 문에 의해서 특정값을 되돌려줌 저장프로시저는 EXEC 에 의해서 실행되지만 함수는 주로 SELECT 문에 포함되어 실행됨(예외도있음) 함수의 종류 시스템 함수 사용자 정의 함수 예제 USE pubs IF object_id('dbo.sfn_test') IS NOT NULL DROP FUNCTION dbo.sfn_test1 GO CREATE FUNCTION dbo.sfn_test1 (@myinput varchar(20)) RETURNS VARCHAR(21) -- 함수는 RETURN 이 있다 AS BEGIN IF @myinput IS NULL SET @myinput = ..
-
DB 프로시저 묶기 INS(삽입), UPD(수정), DEL(삭제), SEL(전체), SEA(하나)Database/MS-SQL 2008. 10. 16. 11:21
모듈화~! 실무에서는 어렇게 많이 쓴다 5개의 프로시저를 하나의 프로시저로 묶은것 USE Pubs IF object_id('usp_JobsProcess') IS NOT NULL DROP PROC usp_JobsProcess GO CREATE PROC usp_JobsProcess -- 프로세스 묶었기때문에 이름정했다 -- 아까와다른점 매개변수가 5개가있다 @job_id smallint = 0 , @job_descvarchar(50) = NULL -- NOT NULL & DEFAULT(s) , @min_lvltinyint = NULL-- 디폴트 NULL , @max_lvltinyint = NULL-- 디폴트 NULL , @prc_typechar(3) = 'SEL'-- 임으로 만든것 prc_type 디폴트 '..
-
Transact SQLWriter/Technical Book 2008. 10. 16. 10:55
Transact SQL 지은이 : 켄 헨더슨 / 옮긴이 : 이종철 정가 : 28,000원 724쪽 / 판형 : B5 / 1판 출간일 : 2002년 11월 01일 ISBN-10 : 8995300922 ISBN-13 : 9788995300923 (목차) (독자리뷰) (부록CD) 저자소개켄 헨더슨 (Ken Henderson) 세계적으로 지명도 높은 컨설턴트이며 DBMS 설계자로서, 미(美) 공군·해군, H&R Block, Travelers Insurance, JP Morgan, CIA, Owens-Corning, NA Insurance 등과 같은 고객사(社)를 대상으로 클라이언트/서버 프로젝트에 대한 컨설팅을 수행하였다. 그는 클라이언트/서버 환경과 DBMS 개발에 관한 다섯 권의 책을 집필하였으며, Soft..
-
저장 프로시저 수정문 삭제문 셀렉트문Database/MS-SQL 2008. 10. 16. 10:34
프로시저 관련 파일 프로시저.zip문을 조금 수정해야함 오타있음 에러관련 함수프로시저 아래는 변수바꾸기 팁 MakeErrMag는 함수프로시져 프로시저 수정 USE Pubs IF object_id('usp_jobsUpdate') IS NOT NULL -- 컨트롤 + H눌러서 이름 한꺼번에 바꾸기 DROP PROC usp_jobsUpdate GO CREATE PROC usp_jobsUpdate ( @job_id smallint --주 키 , @job_desc varchar(50) = NULL-- 디폴트값 NULL , @min_lvl tinyint = NULL-- 디폴트값 NULL , @max_lvl tinyint = NULL-- 디폴트값 NULL ) AS BEGIN TRAN DECLARE @ERR int I..
-
닷넷 클래스 object is 연산자 GetHashCode().NET/C# Basic 2008. 10. 16. 00:42
닷넷 클래스 object object도 일종의 클래스 이므로 내부에 맴버를 가진다 생성자는 아무것도 하지않는 디폴트생성자만 정의되어있으면 필드, 상수, 프로퍼티 인덱서 이벤트등은 가지지않는다.루트 클래스의 맴버는 모든 후손에게 상속되므로 메모리를 소모하는 멤버는 포항하기 어렵다 만약 object에 40바이트의 필드가 있다면 닷넷의 모든 객체는 최소 40바이트 이상으로 되어야하므로 메모리 낭비가 너무 심해질것이다 그래서 객체를 관리하는 일반적인 메서드만을 가진 object 로부터 파생된 모든클래스의 객체들은 이메서드를 가지는 셈이다 ToString public virtual 객체를 문자열 형태로 표현한다 티폴트로 클래스 이름을 리턴하는 데 필요시 재정의할수있다 GetType public 객체의 타입정보를 ..
-
닷넷 클래스 리플렉션 reflection.NET/C# Basic 2008. 10. 15. 18:00
클래스 라이브러리 닷넷 기본 클래스 라이브러리를 사용하면 개발 시간을 많이 단축할 수 있다 제공된 클래스를 생성하거나 상속받아서 새로운 클래스를 정의 System 네임스페이스는 기본 클래스를 모아둔 네임스페이스 System.Object 객체를 비롯해서 기본 데이터형과 같은 기본 클래스가 정의 리플렉션 GetType 메서드는 클래스를 나타내는 Type 객체를 리턴하는 메서드 Type 객체를 이용하면 실행 타임에 클래스에 대한 다양한 정보를 구할 수 있다 Type type = pt.GetType(); FieldInfo [] finfo = type.GetFields(); Type 객체로부터 클래스 정보를 구할 수 있는 방법을 리플렉션(reflection) 이라 한다 리플렉션을 통해서 알아낼 수 있는 정보에는 ..
-
클래스관련 const 상수 readonly 구조체관련 GetType() , is as.NET/C# Basic 2008. 10. 15. 14:48
using System; class Sizes { public const int Medium = 100; // 상수로써 사용되는것 const 항상동일한수 public const int Large = 105;// const 라고 붙은것은 별도의 객체생성없이도 가능 public const int XLarge = 110; } class Shirt { public static void Main() { while(true) { string s; Console.WriteLine("치수 기호를 입력하세요. (M)edium (L)arge (X)Large (q)uit"); s = Console.ReadLine(); if(s == "q") break; switch(s) { case "M" : Console.WriteLin..
-
abstract interfaceWriter/WarmingUp Code 2008. 10. 15. 14:17
using System; interface IAdd { int Add(int a, int b); } interface IMinus { int Minus(int a , int b); } abstract class abMethod { public int Add(int a, int b) { int tot = a+b; return tot; } public abstract int Minus(int a, int b); } class NewInter : IAdd , IMinus { public int Add(int a, int b) { int add= a+b; return add; } public int Minus(int a, int b) { int m = a-b; return m; } } class ABtest :..
-
DB 저장프로시저 연습 프로시저 INSERT 문Database/MS-SQL 2008. 10. 15. 11:15
프로시저 수정후~!!!!!!! 만들어져서 저장되는시간이걸린다 그래서 수정후 바로 적용안되는 경우가 있다 만들고나서 10초정도 딜레이한 시간이 필요하다 USE pubs USE pubs CREATE PROC au_info @lastname varchar(40), @firstname varchar(20) AS SELECT a.au_lname, a.au_fname, t.title, p.pub_name FROM authors AS a INNER JOIN titleauthor AS ta ON a.au_id = ta.au_id INNER JOIN titles AS t ON t.title_id = ta.title_id INNER JOIN publishers AS p ON t.pub_id = p.pub_id WHERE ..
-
프로퍼티 인덱서.NET/C# Basic 2008. 10. 15. 06:11
///// 프로퍼티 ///////// using System; class test { private int a; public int A { get { Console.Write("get"); this.a = a+2; return a; } set { Console.WriteLine("set"); this.a = value; } } } class jks { static void Main() { test t = new test(); t.A = 2; Console.WriteLine("{0}",t.A); } } using System; class jksPro { private string Name; public string NameP { get { string newName = this.Name + "추가문장"; ..
-
연산자 메서드 operator +(), operator-() , 연산자 오버로딩?.NET/C# Basic 2008. 10. 15. 05:37
연산자 메서드를 부르려면 해당 연산자를 사용하며, 연산자를 사용하면 코드가 훨씬 직관적이기 때문에 이해하기 쉬워진다 using System; class Point { public int x; public int y; public Point( int x, int y ) { this.x = x; this.y = y; } public override string ToString() { // (x,y) 값 return String.Format("({0},{1})", x, y ); } // + 연산자 메서드 public static Point operator +(Point pt1, Point pt2) { return (new Point(pt1.x + pt2.x, pt1.y + pt2.y)); } // - 연산자 ..
-
static정적맴버 배열 연산자 is/as foreach 문 메서드 오버로딩 메서드 가변 인자.NET/C# Basic 2008. 10. 14. 21:41
정적(static) 멤버 일반적인 객체 사용 방법은 클래스를 정의하고, 여러 개의 인스턴스를 생성 현재 생성된 총 인스턴스 수를 구하려면 정수형 변수를 두고 인스턴스를 생성할 때마다 하나씩 증가 인스턴스간에 공유해야 하는 값이 필요한 경우, 정적(static) 멤버를 사용 using System; class Point { public Point() { bbb++; Console.WriteLine("생성"+ bbb); } public int bbb = 0; // static int bbb = 0;v // 스택틱하면 값이 더해진다 } class jks { static void Main() { Point pt = new Point(); Point pt1 = new Point(); } } 배열////// usi..
-
인터페이스(interface) 와 추상화클래스(abstract) 예제.NET/C# Basic 2008. 10. 14. 17:03
using System; namespace test_cal { interface IAdd { int Add(int i, int j); } interface IMnus { int Minus(int i, int j); } abstract class abMethod { public int Add(int i , int j) { int tot = i +j; return tot; } public abstract int Minus(int i ,int j); } class NewabMethod : abMethod { public override int Minus(int i, int j) { int m = i -j; return m; } } class NewInter : IAdd, IMnus { public int Ad..
-
저장프로시저 예제Database/MS-SQL 2008. 10. 14. 12:40
USE pubs GO ALTER PROC usp_titleSelectArow ( @title_id VARCHAR(6) = 'MC2222', @result CHAR(12) OUTPUT-- 값을 돌려받기위한 매개변수 값을 출력하기위해쓴다 )AS-- 만약에 OUTPUT 이없으면 대체 -> @pub_id CHAR(4) = '1389' SELECT @result = type FROM titles-- type 이라는글자가 @result에들어간다 WHERE title_id = @title_id -- 만약에 AND pub_id = @pub_id 추가~!! GO SELECT type FROM titles WHERE title_id = 'BU1032' -- ,MC2222 DECLARE @res CHAR(12) -- 변수 ..
-
-
저장프로시저와 사용자 지정함수 사용예Database/MS-SQL 2008. 10. 14. 11:13
C#에서 비교 프로시저(Procedure) : 리턴값없으면 ---- 저장프로시저와는 다른말 public void test() { } function : 리런값있으면 평션 public void test() { return; } 개념 저장 프로시저(Stored Procedure)란 SQL Server에서 제공되는 프로그래밍 기능 저장 프로시저는 한마디로 쿼리문의 집합으로 어떠한 동작을 일괄 처리하기 위한 용도로 사용 구문 형식 CREATE { PROC | PROCEDURE } [schema_name.] procedure_name [ ; number ] [ { @parameter [ type_schema_name. ] data_type } [ VARYING ] [ = default ] [ [ OUT [ PU..
-
데이터 베이스 LOCK(잠금) DEAD LOCK(교착상태)Database/MS-SQL 2008. 10. 14. 10:50
개념 한 사용자가 데이터를 사용하고 있을 경우에, 다른 사용자가 그 데이터를 변경하지 못하도록 하는 것 데이터베이스의 일관성을 위해서 필요함 트랜잭션 격리 수준 (Transaction Isolation Level)의 종류 READ UNCOMMITTED (커밋되지 않은 읽기) READ COMMITTED (커밋된 읽기) SQL Server 2005의 디폴트 값 REPEATABLE READ (반복된 읽기) SNAPSHOT (스냅숏) SERIALIZABLE (직렬화 가능) 여러사용자가 동시에 하나의 데이터에 접근해서 발생하는 문제 Dirty Read (더티 리드, 커밋되지 않은 데이터를 읽기) Unrepeatable Read (반복되지 않은 읽기) Phantom Read (팬텀, 가상읽기) 교착상태(Dead..
-
-
데이터베이스 트렌젝션 TRAN 예제Database/MS-SQL 2008. 10. 14. 10:39
--/////////////////// 트랜젝션 연습 /////////////////////// CREATE TABLE #tranTest-- # 이나 ## 이면 임시 테이블을 말함 ( id INT NOT NULL, msg NVARCHAR(2) NOT NULL ) USE tempdb--임시페이블사용 --EXEC sp_help #tranTest --ALTER TABLE #tranTest --DROP CONSTRAINT PK__#tranTest_________29221CFB DECLARE @i INT --- 데이터 삽입절 SET @i = 1--- 데이터 삽입절 WHILE @i < 120--- 데이터 삽입절 BEGIN--- 데이터 삽입절 INSERT INTO #tranTest (id, msg)--- 데이터 삽입..
-
델리게이트 이벤트 소스 노가다 2Writer/WarmingUp Code 2008. 10. 14. 00:18
using System; class MainApp { delegate void stuff(); static void Main() { stuff s = new stuff(sugar); stuff c = new stuff(cream); stuff m = new stuff(milk); stuff cafe = new stuff(coffee); Console.WriteLine("비엔나 커피 만들기"); stuff vienna = s + c + cafe; vienna(); Console.WriteLine(); stuff cafeaulait = s + m + cafe; cafeaulait(); Console.WriteLine(); stuff black = cafeaulait - m - s; black(); Conso..
-
델리게이트 이벤트 소스 노가다Writer/WarmingUp Code 2008. 10. 13. 21:40
using System; class MainApp { public delegate void Mix(string s);// 델레게이트 선언 public static void Coffee(string s) { Console.WriteLine("{0}",s); } public static void CoCoa(string s) { Console.WriteLine("{0}",s); } public static void Main() { Mix Tea = new Mix(Coffee); Tea("salt"); Tea = new Mix(CoCoa); Tea("milk"); } } using System; class delTest { public delegate void Mix(string s); public static..
-
C# Delegate와 Event 중요.NET/C# Basic 2008. 10. 13. 14:07
모르겠으니까 예제 외우자 낄낄낄~~~!!! [8.Delegate와 Event예제 \ delegate.cs] using System; class MainApp { public delegate void Mix(string s); // 델리게이트 선언 public static void Coffee(string s) { Console.WriteLine("this Coffee is Mixed with {0} ", s); } public static void CoCoa(string s) { Console.WriteLine("this CoCoa is Mixed with {0} ", s); } public static void Main() { Mix Tea = new Mix(Coffee); //할당된 델리게이트는 Co..
-
오픈과제 02.doc 33번~Database/MS-SQL 2008. 10. 13. 11:49
use study_exam2 SELECT * ---- 33번 FROM Student, MAJOR -- student=부모, major= 자식 WHERE student.MajorCode = 1 AND major.majorCode =1 SELECT * FROM --33번 Student AS s, Major AS m WHERE s.MajorCode = m.MajorCode AND -- 네츄럴 조인 m.MajorName='컴퓨터공학과' SELECT * FROM --33번 Student AS s INNER JOIN Major AS m ON s.MajorCode = m.MajorCode AND -- 이너조인 m.MajorName='컴퓨터공학과' SELECT * ----- 34번 FROM student, major ..
-
셀렉트문 팁 SELECT 28번 문제설명 + 서브 쿼리 중요Database/MS-SQL 2008. 10. 13. 11:45
SELECT * FROM 테이블명 WHERE--1 GROUP BY--2 HAVING--3 ORDER BY--4 많이쓴다 USE Study_Exam GO IF (OBJECT_ID('STUDENT') IS NOT NULL) DROP TABLE STUDENT CREATE TABLE STUDENT ( sno NCHAR(3) PRIMARY KEY, --학번 gwaCode NCHAR(2) NOT NULL DEFAULT '', --학과코드 sname NVARNCHAR(20) NOT NULL DEFAULT '', --이름 gender NCHAR(1) NOT NULL DEFAULT 'M', --성별구분 : M은 남성, F는 여성 score TINYINT NOT NULL DEFAULT 0 --점수 ) --테이블에 임의의 ..
-
Console.Read() 와 Console.ReadLine() 차이.NET/C# Basic 2008. 10. 10. 20:12
using System; class whileTest { public static void Main() { bool ugiy = false; bool fool = false; Console.WriteLine("정신 교정 프로그램"); while (!(ugiy && fool)) { Console.WriteLine("당신은 잘생겼습니까? y/n"); if(Console.ReadLine() == "n") //
-
흐름 제어 예제 기본문법 if for while swich foreach break continue.NET/C# Basic 2008. 10. 10. 20:11
using System; class GenderTest { public static void Main() { Console.WriteLine("아유보이? (y)/(n)"); char gender = (char)Console.Read(); if( gender == 'y') Console.WriteLine("남자이시군요"); else if (gender == 'n') Console.WriteLine("여자이시군요"); else Console.WriteLine("잘못된 성별을 입력하셨습니다"); } } using System; class cyon { public static void Main() { Console.WriteLine("요일을 입력하세요"); char day = (char)Console.Read(..
-
연산자 오버로딩 - 인덱스.NET/C# Basic 2008. 10. 10. 17:27
class Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } public override string ToString() { //(x,y)값 return String.Format("({0},{1})",x,y); } // + 연산자 메서드 public static Point operator +(Point pt1, Point pt2) { return (new Point(pt1.x + pt2.x, pt1.y + pt2.y)); } // - 연산자 메서드 public static Point operator -(Point pt1, Point pt2) { return (new Point(pt1.x - p..
-
C# 사용 개념 대충 순서 대충보는거 대충.NET/C# Basic 2008. 10. 10. 14:40
///////////////////////////////// 콘솔 ////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using Calculator; // 추가~~~ namespace ConsoleApplication37 { class Program { static void Main(string[] args) { int i = int.Parse(Console.ReadLine()); int j = int.Parse(Console.ReadLine()); Cal c1 = new Cal(); int k = c1.Add(i,j); int o = c1.Minus(i,j); } }..