Skip to content

Instantly share code, notes, and snippets.

@lekhanh1234
Last active October 6, 2016 09:05
Show Gist options
  • Select an option

  • Save lekhanh1234/375e85b4c5502e69b14273d1ac40652b to your computer and use it in GitHub Desktop.

Select an option

Save lekhanh1234/375e85b4c5502e69b14273d1ac40652b to your computer and use it in GitHub Desktop.

Fix Error cannot connet to sqlexpress

  • goto service
  • find Sql Server Agent
  • turn it on

Create database Company with:

  • Employee(Id, Name, FullName, BirthDay, Gender, Address, Salary, LeaderId, DepartmentId)

– Department(DepartmentId, DepartmentName, Leader)

– DEAN(MADA, TENDA, DD_DA, PHONG)

– THANNHAN(MANV, TEN_TN, NS, GT, QUANHE)

– NV_DEAN(MANV, MADA, SOGIO)

– PHONGBAN_DD(MAPB, DD)

Create database

  • Syntax:
CREATE DATABASE <DatabaseName>
  • Example:
CREATE DATABASE Company

Create table in database

  • Syntax:
CREATE TABLE <TableName>
(
  ColumnName1 data_type(size),
  ColumnName2 data_type(size),  
  ColumnName3 data_type(size),
  ....
)
  • Example: create table Employee(Id, Name, FullName, BirthDay, Gender, Address, Salary, LeaderId, DepartmentId)
CREATE TABLE Employee
(
  Id char(10),
  Name nchar(10),
  FullName nchar(30),
  BirthDay datetime,
  Gender nchar(10) check (Gender in (N'male', N'female')),
  Address nchar(50),
  Salary int default 5000,
  LeaderId char(10),
  DepartmentId char(10),
  primary key (Id)
)

Change column in table

not null

  • Syntax:
ALTER TABLE <TableName>
ALTER COLUMN <ColumnName> datatype not null
  • Example:
ALTER TABLE Employee
ALTER COLUMN Name nchar(10) not null

SQL PRIMARY KEY Constraint on ALTER TABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment